Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(135)

Side by Side Diff: src/data_plan_unittest.cc

Issue 4114002: cashew: data plans: used bytes should be optional for unlimited plans (Closed) Base URL: ssh://git@gitrw.chromium.org:9222/cashew.git
Patch Set: jglasgow review fixes Created 10 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/data_plan.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2010 The Chromium OS Authors. All rights reserved. 1 // Copyright (c) 2010 The Chromium OS Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <base/json/json_reader.h>
6 #include <base/scoped_ptr.h>
5 #include <gtest/gtest.h> 7 #include <gtest/gtest.h>
6 8
7 #include "src/data_plan.h" 9 #include "src/data_plan.h"
10 #include "src/policy.h"
8 11
9 namespace cashew { 12 namespace cashew {
10 13
11 // test fixture for DataPlan unit tests 14 // test fixture for DataPlan unit tests
12 class DataPlanTest: public ::testing::Test { 15 class DataPlanTest: public ::testing::Test {
13 protected: 16 protected:
14 DataPlanTest() {} 17 DataPlanTest() : policy_(NULL) {}
15 virtual ~DataPlanTest() {} 18
16 virtual void SetUp() {} 19 virtual ~DataPlanTest() {
17 virtual void TearDown() {} 20 EXPECT_TRUE(policy_ == NULL);
21 }
22
23 virtual void SetUp() {
24 EXPECT_TRUE(policy_ == NULL);
25 policy_ = Policy::GetPolicy(kTestCarrierName);
26 ASSERT_TRUE(policy_ != NULL);
27 }
28
29 virtual void TearDown() {
30 delete policy_;
31 policy_ = NULL;
32 }
33
34 // hardcoded JSON data plan representations
35 static const char *kMeteredWithUsedBytesJSON;
36 static const char *kMeteredWithNoUsedBytesJSON;
37 static const char *kUnlimitedWithUsedBytesJSON;
38 static const char *kUnlimitedWithNoUsedBytesJSON;
39
40 // test carrier for constructing policy
41 static const char *kTestCarrierName;
42
43 Policy *policy_;
18 }; 44 };
19 45
20 typedef DataPlanTest DataPlanDeathTest; 46 typedef DataPlanTest DataPlanDeathTest;
21 47
48 const char *DataPlanTest::kMeteredWithUsedBytesJSON =
49 "{\"lastUpdate\" : \"2010-09-20T12:01:00Z\","
50 "\"planName\" : \"Super-Awesome Chromium OS Plan\","
51 "\"planType\" : \"METERED_PAID\","
52 "\"maxBytes\" : 104857600,"
53 "\"usedBytes\" : 52428800,"
54 "\"expirationTime\" : \"2010-09-30T23:59:59\","
55 "\"startTime\" : \"2010-09-01T00:00:00\""
56 "}";
57
58 const char *DataPlanTest::kMeteredWithNoUsedBytesJSON =
59 "{\"lastUpdate\" : \"2010-09-20T12:01:00Z\","
60 "\"planName\" : \"Super-Awesome Chromium OS Plan\","
61 "\"planType\" : \"METERED_PAID\","
62 "\"maxBytes\" : 104857600,"
63 "\"expirationTime\" : \"2010-09-30T23:59:59\","
64 "\"startTime\" : \"2010-09-01T00:00:00\""
65 "}";
66
67 const char *DataPlanTest::kUnlimitedWithUsedBytesJSON =
68 "{\"lastUpdate\" : \"2010-09-20T12:01:00Z\","
69 "\"planName\" : \"All-You-Can-Eat Day Pass\","
70 "\"planType\" : \"UNLIMITED\","
71 "\"usedBytes\" : 52428800,"
72 "\"expirationTime\" : \"2010-09-20T23:59:59\","
73 "\"startTime\" : \"2010-09-20T00:00:00\""
74 "}";
75
76 const char *DataPlanTest::kUnlimitedWithNoUsedBytesJSON =
77 "{\"lastUpdate\" : \"2010-09-20T12:01:00Z\","
78 "\"planName\" : \"All-You-Can-Eat Day Pass\","
79 "\"planType\" : \"UNLIMITED\","
80 "\"expirationTime\" : \"2010-09-20T23:59:59\","
81 "\"startTime\" : \"2010-09-20T00:00:00\""
82 "}";
83
84 const char *DataPlanTest::kTestCarrierName = "Test Carrier";
85
22 TEST_F(DataPlanTest, UtcTimeString) { 86 TEST_F(DataPlanTest, UtcTimeString) {
23 static const char *kTimeStringToTest = "2010-09-20T23:59:59Z"; 87 static const char *kTimeStringToTest = "2010-09-20T23:59:59Z";
24 base::Time time; 88 base::Time time;
25 bool result = DataPlan::TimeFromIso8601(kTimeStringToTest, &time, false); 89 bool result = DataPlan::TimeFromIso8601(kTimeStringToTest, &time, false);
26 EXPECT_TRUE(result); 90 EXPECT_TRUE(result);
27 struct base::Time::Exploded exploded; 91 struct base::Time::Exploded exploded;
28 time.UTCExplode(&exploded); 92 time.UTCExplode(&exploded);
29 EXPECT_EQ(2010, exploded.year); 93 EXPECT_EQ(2010, exploded.year);
30 EXPECT_EQ(9, exploded.month); 94 EXPECT_EQ(9, exploded.month);
31 EXPECT_EQ(20, exploded.day_of_month); 95 EXPECT_EQ(20, exploded.day_of_month);
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 EXPECT_FALSE(result); 138 EXPECT_FALSE(result);
75 } 139 }
76 140
77 TEST_F(DataPlanDeathTest, NullTimeOutPtr) { 141 TEST_F(DataPlanDeathTest, NullTimeOutPtr) {
78 static const char *kTimeStringToTest = "2010-09-20T23:59:59Z"; 142 static const char *kTimeStringToTest = "2010-09-20T23:59:59Z";
79 EXPECT_EXIT(DataPlan::TimeFromIso8601(kTimeStringToTest, NULL, false), 143 EXPECT_EXIT(DataPlan::TimeFromIso8601(kTimeStringToTest, NULL, false),
80 testing::KilledBySignal(SIGABRT), 144 testing::KilledBySignal(SIGABRT),
81 "Check failed: 'time_out' Must be non NULL"); 145 "Check failed: 'time_out' Must be non NULL");
82 } 146 }
83 147
148 TEST_F(DataPlanTest, FromDictionaryValueMeteredWithUsedBytes) {
149 scoped_ptr<Value> value(base::JSONReader::Read(kMeteredWithUsedBytesJSON,
150 true));
151 ASSERT_TRUE(value != NULL);
152 ASSERT_TRUE(value->IsType(Value::TYPE_DICTIONARY));
153 const DictionaryValue *dict_value =
154 static_cast<const DictionaryValue*>(value.get());
155 DataPlan *plan = DataPlan::FromDictionaryValue(dict_value, policy_);
156 // we expect the call to have succeeeded, with the new data plan's used bytes
157 // property set to the value that was present in the JSON representation
158 ASSERT_TRUE(plan != NULL);
159 EXPECT_EQ(52428800, plan->GetDataBytesUsed());
160 }
161
162 TEST_F(DataPlanTest, FromDictonaryValueMeteredWithNoUsedBytes) {
163 scoped_ptr<Value> value(base::JSONReader::Read(kMeteredWithNoUsedBytesJSON,
164 true));
165 ASSERT_TRUE(value != NULL);
166 ASSERT_TRUE(value->IsType(Value::TYPE_DICTIONARY));
167 const DictionaryValue *dict_value =
168 static_cast<const DictionaryValue*>(value.get());
169 DataPlan *plan = DataPlan::FromDictionaryValue(dict_value, policy_);
170 // the JSON representation for metered plans must include used bytes, so we
171 // expect the call to have failed
172 EXPECT_TRUE(plan == NULL);
173 }
174
175 TEST_F(DataPlanTest, FromDictionaryValueUnlimitedWithUsedBytes) {
176 scoped_ptr<Value> value(base::JSONReader::Read(kUnlimitedWithUsedBytesJSON,
177 true));
178 ASSERT_TRUE(value != NULL);
179 ASSERT_TRUE(value->IsType(Value::TYPE_DICTIONARY));
180 const DictionaryValue *dict_value =
181 static_cast<const DictionaryValue*>(value.get());
182 DataPlan *plan = DataPlan::FromDictionaryValue(dict_value, policy_);
183 // we expect the call to have succeeeded, with the new data plan's used bytes
184 // property set to the value that was present in the JSON representation
185 ASSERT_TRUE(plan != NULL);
186 EXPECT_EQ(52428800, plan->GetDataBytesUsed());
187 }
188
189 TEST_F(DataPlanTest, FromDictionaryValueUnlimitedWithNoUsedBytes) {
190 scoped_ptr<Value> value(base::JSONReader::Read(kUnlimitedWithNoUsedBytesJSON,
191 true));
192 ASSERT_TRUE(value != NULL);
193 ASSERT_TRUE(value->IsType(Value::TYPE_DICTIONARY));
194 const DictionaryValue *dict_value =
195 static_cast<const DictionaryValue*>(value.get());
196 DataPlan *plan = DataPlan::FromDictionaryValue(dict_value, policy_);
197 // it's optional for the JSON representation for unlimited plans to include
198 // used bytes, so we expect the call to have succeeded. The new data plan's
199 // used bytes property should have been set to the default of 0.
200 ASSERT_TRUE(plan != NULL);
201 EXPECT_EQ(0, plan->GetDataBytesUsed());
202 }
203
84 } // namespace cashew 204 } // namespace cashew
OLDNEW
« no previous file with comments | « src/data_plan.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698