blob: 5537e97057f633fff6a9a6460f2ceecb34635e71 [file] [log] [blame]
Ben Chanb39cb312012-11-01 22:55:25 -07001// Copyright (c) 2012 The Chromium OS Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include "shill/cellular_operator_info.h"
6
7#include <base/file_util.h>
8#include <gtest/gtest.h>
9
10using std::string;
11
12namespace shill {
13
14namespace {
15
16const char kTestInfoFileContent[] =
Ben Chan20228c02012-11-04 21:43:50 -080017 "#\n"
18 "# Comments\n"
19 "#\n"
Ben Chanb39cb312012-11-01 22:55:25 -070020 "[000001]\n"
21 "OLP.URL=https://testurl\n"
22 "OLP.Method=POST\n"
23 "OLP.PostData=imei=${imei}&iccid=${iccid}\n"
24 "\n"
25 "[000002]\n"
26 "OLP.URL=https://testurl2\n"
27 "\n"
28 "[000003]\n"
29 "Name=test\n";
30
31} // namespace
32
33class CellularOperatorInfoTest : public testing::Test {
34 public:
35 CellularOperatorInfoTest() : info_(&glib_) {}
36
37 protected:
38 void SetUp() {
39 ASSERT_TRUE(file_util::CreateTemporaryFile(&info_file_path_));
40 ASSERT_EQ(arraysize(kTestInfoFileContent),
41 file_util::WriteFile(info_file_path_, kTestInfoFileContent,
42 arraysize(kTestInfoFileContent)));
43 }
44
45 void TearDown() {
46 ASSERT_TRUE(file_util::Delete(info_file_path_, false));
47 }
48
49 GLib glib_;
50 FilePath info_file_path_;
51 CellularOperatorInfo info_;
52};
53
54TEST_F(CellularOperatorInfoTest, GetOLP) {
55 EXPECT_TRUE(info_.Load(info_file_path_));
56
57 CellularService::OLP olp;
58 EXPECT_TRUE(info_.GetOLP("000001", &olp));
59 EXPECT_EQ("https://testurl", olp.GetURL());
60 EXPECT_EQ("POST", olp.GetMethod());
61 EXPECT_EQ("imei=${imei}&iccid=${iccid}", olp.GetPostData());
62
63 EXPECT_TRUE(info_.GetOLP("000002", &olp));
64 EXPECT_EQ("https://testurl2", olp.GetURL());
65 EXPECT_EQ("", olp.GetMethod());
66 EXPECT_EQ("", olp.GetPostData());
67
68 EXPECT_FALSE(info_.GetOLP("000003", &olp));
69 EXPECT_FALSE(info_.GetOLP("000004", &olp));
70}
71
72} // namespace shill