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

Side by Side Diff: developer_switch_unittest.cc

Issue 3530001: first cut: establishes base helper classes and main (Closed) Base URL: http://git.chromium.org/git/cros_boot_mode.git
Patch Set: truncation is bad, m'kay. . . Created 10 years, 2 months 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 | « developer_switch.cc ('k') | helpers.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4 //
5 // Tests for cros_boot_mode::DeveloperSwitch default behavior.
6 // This also acts as the canonical unittest for PlatformSwitch default
7 // behavior.
8 #include "developer_switch.h"
9
10 #include <base/basictypes.h>
11 #include <base/file_util.h>
12 #include <gtest/gtest.h>
13 #include <string>
14
15 class DeveloperSwitchTest : public ::testing::Test {
16 public:
17 void SetUp() {
18 EXPECT_TRUE(file_util::CreateNewTempDirectory("", &temp_dir_));
19 switch_file_path_ = temp_dir_.value();
20 switch_file_path_.append("chsw");
21 switch_.set_platform_file_path(switch_file_path_.c_str());
22 }
23
24 void TearDown() {
25 file_util::Delete(temp_dir_, true);
26 }
27
28 void ExpectPosition(int pos) {
29 static const char *kUnsupported = "unsupported";
30 EXPECT_EQ(pos, switch_.value());
31 // If the position is -1, it is does not index.
32 const char *expected_c_str = kUnsupported;
33 if (pos >= 0)
34 expected_c_str = cros_boot_mode::PlatformSwitch::kPositionText[pos];
35 EXPECT_STREQ(expected_c_str, switch_.c_str());
36 }
37 protected:
38 std::string switch_file_path_;
39 FilePath temp_dir_;
40 cros_boot_mode::DeveloperSwitch switch_;
41 };
42
43
44 TEST_F(DeveloperSwitchTest, Disabled) {
45 EXPECT_EQ(file_util::WriteFile(FilePath(switch_file_path_), "0", 2), 2);
46 switch_.Initialize();
47 ExpectPosition(cros_boot_mode::PlatformSwitch::kDisabled);
48 }
49
50 TEST_F(DeveloperSwitchTest, DisabledWithOtherSwitches) {
51 EXPECT_EQ(file_util::WriteFile(FilePath(switch_file_path_), "528", 4), 4);
52 switch_.Initialize();
53 ExpectPosition(cros_boot_mode::PlatformSwitch::kDisabled);
54 }
55
56 TEST_F(DeveloperSwitchTest, Enabled) {
57 EXPECT_EQ(file_util::WriteFile(FilePath(switch_file_path_), "32", 3), 3);
58 switch_.Initialize();
59 ExpectPosition(cros_boot_mode::PlatformSwitch::kEnabled);
60 }
61
62 TEST_F(DeveloperSwitchTest, EnabledWithOtherSwitches) {
63 EXPECT_EQ(file_util::WriteFile(FilePath(switch_file_path_), "544", 4), 4);
64 switch_.Initialize();
65 ExpectPosition(cros_boot_mode::PlatformSwitch::kEnabled);
66 }
67
68 TEST_F(DeveloperSwitchTest, EnabledWithOtherSwitches2) {
69 EXPECT_EQ(file_util::WriteFile(FilePath(switch_file_path_), "4128", 5), 5);
70 switch_.Initialize();
71 ExpectPosition(cros_boot_mode::PlatformSwitch::kEnabled);
72 }
73
74 TEST_F(DeveloperSwitchTest, EnabledWithOtherSwitches3) {
75 EXPECT_EQ(file_util::WriteFile(FilePath(switch_file_path_), "65535", 6), 6);
76 switch_.Initialize();
77 ExpectPosition(cros_boot_mode::PlatformSwitch::kEnabled);
78 }
79
80 TEST_F(DeveloperSwitchTest, BadTruncationMakesUnsupported) {
81 EXPECT_EQ(file_util::WriteFile(FilePath(switch_file_path_), "100000", 7), 7);
82 switch_.Initialize();
83 ExpectPosition(cros_boot_mode::PlatformSwitch::kUnsupported);
84 }
85
86 TEST_F(DeveloperSwitchTest, MissingFile) {
87 switch_.Initialize();
88 ExpectPosition(cros_boot_mode::PlatformSwitch::kUnsupported);
89 }
90
91 TEST_F(DeveloperSwitchTest, UnsupportedPlatform) {
92 EXPECT_EQ(file_util::WriteFile(FilePath(switch_file_path_), "-1", 3), 3);
93 switch_.Initialize();
94 ExpectPosition(cros_boot_mode::PlatformSwitch::kUnsupported);
95 }
96
97 TEST_F(DeveloperSwitchTest, EmptyFile) {
98 EXPECT_EQ(file_util::WriteFile(FilePath(switch_file_path_), "", 0), 0);
99 switch_.Initialize();
100 ExpectPosition(cros_boot_mode::PlatformSwitch::kUnsupported);
101 }
OLDNEW
« no previous file with comments | « developer_switch.cc ('k') | helpers.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698