blob: 2a18e0035a6421fbe9d231f99b04dc86342c47d7 [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[] =
17 "[000001]\n"
18 "OLP.URL=https://testurl\n"
19 "OLP.Method=POST\n"
20 "OLP.PostData=imei=${imei}&iccid=${iccid}\n"
21 "\n"
22 "[000002]\n"
23 "OLP.URL=https://testurl2\n"
24 "\n"
25 "[000003]\n"
26 "Name=test\n";
27
28} // namespace
29
30class CellularOperatorInfoTest : public testing::Test {
31 public:
32 CellularOperatorInfoTest() : info_(&glib_) {}
33
34 protected:
35 void SetUp() {
36 ASSERT_TRUE(file_util::CreateTemporaryFile(&info_file_path_));
37 ASSERT_EQ(arraysize(kTestInfoFileContent),
38 file_util::WriteFile(info_file_path_, kTestInfoFileContent,
39 arraysize(kTestInfoFileContent)));
40 }
41
42 void TearDown() {
43 ASSERT_TRUE(file_util::Delete(info_file_path_, false));
44 }
45
46 GLib glib_;
47 FilePath info_file_path_;
48 CellularOperatorInfo info_;
49};
50
51TEST_F(CellularOperatorInfoTest, GetOLP) {
52 EXPECT_TRUE(info_.Load(info_file_path_));
53
54 CellularService::OLP olp;
55 EXPECT_TRUE(info_.GetOLP("000001", &olp));
56 EXPECT_EQ("https://testurl", olp.GetURL());
57 EXPECT_EQ("POST", olp.GetMethod());
58 EXPECT_EQ("imei=${imei}&iccid=${iccid}", olp.GetPostData());
59
60 EXPECT_TRUE(info_.GetOLP("000002", &olp));
61 EXPECT_EQ("https://testurl2", olp.GetURL());
62 EXPECT_EQ("", olp.GetMethod());
63 EXPECT_EQ("", olp.GetPostData());
64
65 EXPECT_FALSE(info_.GetOLP("000003", &olp));
66 EXPECT_FALSE(info_.GetOLP("000004", &olp));
67}
68
69} // namespace shill