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

Side by Side Diff: bootloader_type_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 | « bootloader_type.cc ('k') | common.mk » ('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::BootloaderType default behavior.
6 #include "bootloader_type.h"
7
8 #include <base/basictypes.h>
9 #include <base/file_util.h>
10 #include <base/stringprintf.h>
11 #include <gtest/gtest.h>
12 #include <string>
13
14 class BootloaderTypeTest : public ::testing::Test {
15 public:
16 void SetUp() {
17 EXPECT_TRUE(file_util::CreateNewTempDirectory("", &temp_dir_));
18 type_file_path_ = temp_dir_.value();
19 type_file_path_.append("cmdline");
20 type_.set_platform_file_path(type_file_path_.c_str());
21 }
22 void TearDown() {
23 file_util::Delete(temp_dir_, true);
24 }
25
26 void ExpectType(int type) {
27 static const char *kUnsupported = "unsupported";
28 EXPECT_EQ(type, type_.value());
29 // If the position is -1, it is does not index.
30 const char *expected_c_str = kUnsupported;
31 if (type >= 0)
32 expected_c_str =
33 cros_boot_mode::BootloaderType::kBootloaderTypeText[type];
34 EXPECT_STREQ(expected_c_str, type_.c_str());
35 }
36 protected:
37 std::string type_file_path_;
38 FilePath temp_dir_;
39 cros_boot_mode::BootloaderType type_;
40 };
41
42 TEST_F(BootloaderTypeTest, ChromeOSBare) {
43 std::string contents = StringPrintf("%s",
44 cros_boot_mode::BootloaderType::kSupportedBootloaders[
45 cros_boot_mode::BootloaderType::kChromeOS]);
46
47 EXPECT_EQ(file_util::WriteFile(FilePath(type_file_path_),
48 contents.c_str(), contents.length()),
49 contents.length());
50 type_.Initialize();
51 ExpectType(cros_boot_mode::BootloaderType::kChromeOS);
52 }
53
54 TEST_F(BootloaderTypeTest, ChromeOSSpaces) {
55 std::string contents = StringPrintf(" %s ",
56 cros_boot_mode::BootloaderType::kSupportedBootloaders[
57 cros_boot_mode::BootloaderType::kChromeOS]);
58
59 EXPECT_EQ(file_util::WriteFile(FilePath(type_file_path_),
60 contents.c_str(), contents.length()),
61 contents.length());
62 type_.Initialize();
63 ExpectType(cros_boot_mode::BootloaderType::kChromeOS);
64 }
65
66 TEST_F(BootloaderTypeTest, NoBoundaries) {
67 std::string contents = StringPrintf("x%sx",
68 cros_boot_mode::BootloaderType::kSupportedBootloaders[
69 cros_boot_mode::BootloaderType::kChromeOS]);
70
71 EXPECT_EQ(file_util::WriteFile(FilePath(type_file_path_),
72 contents.c_str(), contents.length()),
73 contents.length());
74 type_.Initialize();
75 ExpectType(cros_boot_mode::BootloaderType::kUnsupported);
76 }
77
78 TEST_F(BootloaderTypeTest, NoStartingBoundary) {
79 std::string contents = StringPrintf("x%s",
80 cros_boot_mode::BootloaderType::kSupportedBootloaders[
81 cros_boot_mode::BootloaderType::kChromeOS]);
82
83 EXPECT_EQ(file_util::WriteFile(FilePath(type_file_path_),
84 contents.c_str(), contents.length()),
85 contents.length());
86 type_.Initialize();
87 ExpectType(cros_boot_mode::BootloaderType::kUnsupported);
88 }
89
90 TEST_F(BootloaderTypeTest, NoTrailingBoundary) {
91 std::string contents = StringPrintf("%sx",
92 cros_boot_mode::BootloaderType::kSupportedBootloaders[
93 cros_boot_mode::BootloaderType::kChromeOS]);
94
95 EXPECT_EQ(file_util::WriteFile(FilePath(type_file_path_),
96 contents.c_str(), contents.length()),
97 contents.length());
98 type_.Initialize();
99 ExpectType(cros_boot_mode::BootloaderType::kUnsupported);
100 }
101
102 TEST_F(BootloaderTypeTest, FirstMatchIsUsed) {
103 std::string contents = StringPrintf(" %s %s ",
104 cros_boot_mode::BootloaderType::kSupportedBootloaders[
105 cros_boot_mode::BootloaderType::kChromeOS],
106 cros_boot_mode::BootloaderType::kSupportedBootloaders[
107 cros_boot_mode::BootloaderType::kEFI]);
108
109 EXPECT_EQ(file_util::WriteFile(FilePath(type_file_path_),
110 contents.c_str(), contents.length()),
111 contents.length());
112 type_.Initialize();
113 ExpectType(cros_boot_mode::BootloaderType::kChromeOS);
114 }
OLDNEW
« no previous file with comments | « bootloader_type.cc ('k') | common.mk » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698