Revert "Reland c91b178b07b0d - Delete dead signin code (SigninGlobalError)"
[chromium-blink-merge.git] / rlz / win / lib / machine_deal_test.cc
blobec0526fde9c78ea6fb618b63bb433bb18b50213c
1 // Copyright (c) 2012 The Chromium 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 // A test application for the MachineDealCode class.
6 //
7 // These tests should not be executed on the build server:
8 // - They assert for the failed cases.
9 // - They modify machine state (registry).
11 // These tests require write access to HKLM and HKCU, unless
12 // rlz_lib::CreateMachineState() has been successfully called.
14 #include "base/logging.h"
15 #include "testing/gmock/include/gmock/gmock.h"
16 #include "testing/gtest/include/gtest/gtest.h"
18 #include "rlz/test/rlz_test_helpers.h"
19 #include "rlz/win/lib/machine_deal.h"
21 class MachineDealCodeHelper : public rlz_lib::MachineDealCode {
22 public:
23 static bool Clear() { return rlz_lib::MachineDealCode::Clear(); }
25 private:
26 MachineDealCodeHelper() {}
27 ~MachineDealCodeHelper() {}
30 class MachineDealCodeTest : public RlzLibTestBase {
33 TEST_F(MachineDealCodeTest, CreateMachineState) {
34 EXPECT_TRUE(rlz_lib::CreateMachineState());
37 TEST_F(MachineDealCodeTest, Set) {
38 MachineDealCodeHelper::Clear();
39 char dcc_50[50];
40 dcc_50[0] = 0;
42 EXPECT_TRUE(rlz_lib::MachineDealCode::Set("dcc_value"));
44 EXPECT_TRUE(rlz_lib::MachineDealCode::Get(dcc_50, 50));
45 EXPECT_STREQ("dcc_value", dcc_50);
47 EXPECT_TRUE(rlz_lib::MachineDealCode::Set("dcc_value_2"));
49 EXPECT_TRUE(rlz_lib::MachineDealCode::Get(dcc_50, 50));
50 EXPECT_STREQ("dcc_value_2", dcc_50);
53 TEST_F(MachineDealCodeTest, Get) {
54 MachineDealCodeHelper::Clear();
55 char dcc_50[50], dcc_2[2];
56 dcc_50[0] = 0;
57 dcc_2[0] = 0;
59 EXPECT_FALSE(rlz_lib::MachineDealCode::Get(dcc_50, 50));
61 EXPECT_TRUE(rlz_lib::MachineDealCode::Set("dcc_value"));
63 EXPECT_TRUE(rlz_lib::MachineDealCode::Get(dcc_50, 50));
64 EXPECT_STREQ("dcc_value", dcc_50);
66 EXPECT_FALSE(rlz_lib::MachineDealCode::Get(dcc_2, 2));
69 TEST_F(MachineDealCodeTest, SetFromPingResponse) {
70 rlz_lib::MachineDealCode::Set("MyDCCode");
71 char dcc_50[50];
73 // Bad responses
75 const char kBadDccResponse[] =
76 "dcc: NotMyDCCode \r\n"
77 "set_dcc: NewDCCode\r\n"
78 "crc32: 1B4D6BB3";
79 EXPECT_FALSE(rlz_lib::MachineDealCode::SetFromPingResponse(
80 kBadDccResponse));
81 EXPECT_TRUE(rlz_lib::MachineDealCode::Get(dcc_50, 50));
82 EXPECT_STREQ("MyDCCode", dcc_50);
84 const char kBadCrcResponse[] =
85 "dcc: MyDCCode \r\n"
86 "set_dcc: NewDCCode\r\n"
87 "crc32: 90707106";
88 EXPECT_FALSE(rlz_lib::MachineDealCode::SetFromPingResponse(
89 kBadCrcResponse));
90 EXPECT_TRUE(rlz_lib::MachineDealCode::Get(dcc_50, 50));
91 EXPECT_STREQ("MyDCCode", dcc_50);
93 // Good responses
95 const char kMissingSetResponse[] =
96 "dcc: MyDCCode \r\n"
97 "crc32: 35F2E717";
98 EXPECT_TRUE(rlz_lib::MachineDealCode::SetFromPingResponse(
99 kMissingSetResponse));
100 EXPECT_TRUE(rlz_lib::MachineDealCode::Get(dcc_50, 50));
101 EXPECT_STREQ("MyDCCode", dcc_50);
103 const char kGoodResponse[] =
104 "dcc: MyDCCode \r\n"
105 "set_dcc: NewDCCode\r\n"
106 "crc32: C8540E02";
107 EXPECT_TRUE(rlz_lib::MachineDealCode::SetFromPingResponse(
108 kGoodResponse));
109 EXPECT_TRUE(rlz_lib::MachineDealCode::Get(dcc_50, 50));
110 EXPECT_STREQ("NewDCCode", dcc_50);
112 const char kGoodResponse2[] =
113 "set_dcc: NewDCCode2 \r\n"
114 "dcc: NewDCCode \r\n"
115 "crc32: 60B6409A";
116 EXPECT_TRUE(rlz_lib::MachineDealCode::SetFromPingResponse(
117 kGoodResponse2));
118 EXPECT_TRUE(rlz_lib::MachineDealCode::Get(dcc_50, 50));
119 EXPECT_STREQ("NewDCCode2", dcc_50);
121 MachineDealCodeHelper::Clear();
122 const char kGoodResponse3[] =
123 "set_dcc: NewDCCode \r\n"
124 "crc32: 374C1C47";
125 EXPECT_TRUE(rlz_lib::MachineDealCode::SetFromPingResponse(
126 kGoodResponse3));
127 EXPECT_TRUE(rlz_lib::MachineDealCode::Get(dcc_50, 50));
128 EXPECT_STREQ("NewDCCode", dcc_50);
130 MachineDealCodeHelper::Clear();
131 const char kGoodResponse4[] =
132 "dcc: \r\n"
133 "set_dcc: NewDCCode \r\n"
134 "crc32: 0AB1FB39";
135 EXPECT_TRUE(rlz_lib::MachineDealCode::SetFromPingResponse(
136 kGoodResponse4));
137 EXPECT_TRUE(rlz_lib::MachineDealCode::Get(dcc_50, 50));
138 EXPECT_STREQ("NewDCCode", dcc_50);
141 TEST_F(MachineDealCodeTest, GetAsCgi) {
142 MachineDealCodeHelper::Clear();
143 char cgi_50[50], cgi_2[2];
144 cgi_50[0] = 0;
145 cgi_2[0] = 0;
147 EXPECT_FALSE(rlz_lib::MachineDealCode::GetAsCgi(cgi_50, 50));
148 EXPECT_STREQ("", cgi_50);
150 EXPECT_TRUE(rlz_lib::MachineDealCode::Set("dcc_value"));
152 EXPECT_TRUE(rlz_lib::MachineDealCode::GetAsCgi(cgi_50, 50));
153 EXPECT_STREQ("dcc=dcc_value", cgi_50);
155 EXPECT_FALSE(rlz_lib::MachineDealCode::GetAsCgi(cgi_2, 2));