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

Side by Side Diff: syzygy/experimental/protect/protect_unittest/protect_app_unittests.cc

Issue 2535563002: Added all code for integrity check transform (Closed)
Patch Set: Created 4 years 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
OLDNEW
(Empty)
1 // Copyright 2013 Google Inc. All Rights Reserved.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14
15 #include "syzygy/experimental/protect/protect_lib/protect_app.h"
16
17 #include "base/strings/utf_string_conversions.h"
18 #include "gmock/gmock.h"
19 #include "gtest/gtest.h"
20 #include "syzygy/core/unittest_util.h"
21 #include "syzygy/pe/unittest_util.h"
22
23 namespace protect {
24
25 namespace {
26 static wchar_t kConfigGoodExistingOutput[] =
27 L"syzygy/experimental/protect/test_data/config-good-existing-output.txt";
28
29 class TestProtectApp : public ProtectApp {
30 public:
31 using ProtectApp::overwrite_;
32 };
33
34 typedef application::Application<TestProtectApp> TestApp;
35
36 class ProtectAppTest : public testing::PELibUnitTest {
37 public:
38 typedef testing::PELibUnitTest Super;
39
40 ProtectAppTest()
41 : cmd_line_(base::FilePath(L"protect.exe")),
42 test_impl_(test_app_.implementation()) {
43 }
44
45 void SetUp() {
46 Super::SetUp();
47
48 logging::SetMinLogLevel(logging::LOG_ERROR);
49
50 // Setup the IO streams.
51 CreateTemporaryDir(&temp_dir_);
52 stdin_path_ = temp_dir_.Append(L"NUL");
53 stdout_path_ = temp_dir_.Append(L"stdout.txt");
54 stderr_path_ = temp_dir_.Append(L"stderr.txt");
55 InitStreams(stdin_path_, stdout_path_, stderr_path_);
56
57 ASSERT_NO_FATAL_FAILURE(ConfigureTestApp(&test_app_));
58
59 config_file_ = temp_dir_.Append(L"config.txt");
60 }
61
62 // Points the application at the fixture's command-line and IO streams.
63 template<typename TestAppType>
64 void ConfigureTestApp(TestAppType* test_app) {
65 test_app->set_command_line(&cmd_line_);
66 test_app->set_in(in());
67 test_app->set_out(out());
68 test_app->set_err(err());
69 }
70
71 // Stashes the current log-level before each test instance and restores it
72 // after each test completes.
73 testing::ScopedLogLevelSaver log_level_saver;
74
75 // @name The application under test.
76 // @{
77 TestApp test_app_;
78 TestApp::Implementation& test_impl_;
79 base::FilePath temp_dir_;
80 base::FilePath stdin_path_;
81 base::FilePath stdout_path_;
82 base::FilePath stderr_path_;
83 // @}
84
85 base::CommandLine cmd_line_;
86 base::FilePath config_file_;
87 };
88
89 } // namespace
90
91 TEST_F(ProtectAppTest, ParseEmptyCommandLineFails) {
92 ASSERT_FALSE(test_impl_.ParseCommandLine(&cmd_line_));
93 }
94
95 TEST_F(ProtectAppTest, ConfigurationFailsExistingOutput) {
96 base::FilePath input_module = testing::GetOutputRelativePath(
97 testing::kTestDllName);
98 base::FilePath output_module = temp_dir_.Append(testing::kTestDllName);
99
100 config_file_ = testing::GetSrcRelativePath(kConfigGoodExistingOutput);
101 cmd_line_.AppendSwitchPath("input-image", input_module);
102 cmd_line_.AppendSwitchPath("output-image", output_module);
103 cmd_line_.AppendSwitchPath("flummox-config-path", config_file_);
104 ASSERT_TRUE(test_impl_.ParseCommandLine(&cmd_line_));
105 }
106
107 TEST_F(ProtectAppTest, ConfigurationLoadsExistingOutput) {
108 base::FilePath input_module = testing::GetOutputRelativePath(
109 testing::kTestDllName);
110 base::FilePath output_module = temp_dir_.Append(testing::kTestDllName);
111
112 config_file_ = testing::GetSrcRelativePath(kConfigGoodExistingOutput);
113 cmd_line_.AppendSwitchPath("input-image", input_module);
114 cmd_line_.AppendSwitchPath("output-image", output_module);
115 cmd_line_.AppendSwitchPath("flummox-config-path", config_file_);
116 cmd_line_.AppendSwitch("overwrite");
117 ASSERT_TRUE(test_impl_.ParseCommandLine(&cmd_line_));
118 }
119
120 } // namespace protect
OLDNEW
« no previous file with comments | « syzygy/experimental/protect/protect_unittest/integrity_check_transform_unittests.cc ('k') | syzygy/pe/pe_file_writer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698