summaryrefslogtreecommitdiffstats
path: root/chrome/browser/chromeos/system/name_value_pairs_parser_unittest.cc
blob: d229126bff9970ff7f4e568e0a1e6990ad055d00 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "chrome/browser/chromeos/system/name_value_pairs_parser.h"

#include "base/basictypes.h"
#include "testing/gtest/include/gtest/gtest.h"

namespace chromeos {
namespace system {

TEST(NameValuePairsParser, TestGetSingleValueFromTool) {
  NameValuePairsParser::NameValueMap map;
  NameValuePairsParser parser(&map);
  const char* command[] = { "/bin/echo", "Foo" };
  EXPECT_TRUE(parser.GetSingleValueFromTool(arraysize(command), command,
                                            "foo"));
  ASSERT_EQ(1U, map.size());
  EXPECT_EQ("Foo", map["foo"]);
}

TEST(NameValuePairsParser, TestParseNameValuePairs) {
  NameValuePairsParser::NameValueMap map;
  NameValuePairsParser parser(&map);
  const std::string contents1 = "foo=Foo bar=Bar\nfoobar=FooBar\n";
  EXPECT_TRUE(parser.ParseNameValuePairs(contents1, "=", " \n"));
  ASSERT_EQ(3U, map.size());
  EXPECT_EQ("Foo", map["foo"]);
  EXPECT_EQ("Bar", map["bar"]);
  EXPECT_EQ("FooBar", map["foobar"]);

  map.clear();
  const std::string contents2 = "foo=Foo,bar=Bar";
  EXPECT_TRUE(parser.ParseNameValuePairs(contents2, "=", ",\n"));
  ASSERT_EQ(2U, map.size());
  EXPECT_EQ("Foo", map["foo"]);
  EXPECT_EQ("Bar", map["bar"]);

  map.clear();
  const std::string contents3 = "foo=Foo=foo,bar=Bar";
  EXPECT_FALSE(parser.ParseNameValuePairs(contents3, "=", ",\n"));

  map.clear();
  const std::string contents4 = "foo=Foo,=Bar";
  EXPECT_FALSE(parser.ParseNameValuePairs(contents4, "=", ",\n"));

  map.clear();
  const std::string contents5 =
      "\"initial_locale\"=\"ja\"\n"
      "\"initial_timezone\"=\"Asia/Tokyo\"\n"
      "\"keyboard_layout\"=\"mozc-jp\"\n";
  EXPECT_TRUE(parser.ParseNameValuePairs(contents5, "=", "\n"));
  ASSERT_EQ(3U, map.size());
  EXPECT_EQ("ja", map["initial_locale"]);
  EXPECT_EQ("Asia/Tokyo", map["initial_timezone"]);
  EXPECT_EQ("mozc-jp", map["keyboard_layout"]);
}

}  // namespace system
}  // namespace chromeos