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

Side by Side Diff: courgette/encode_decode_unittest.cc

Issue 8252011: Add a basic backwards compatibility unittest. (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Fix review nits. Created 9 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
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium 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 <string> 5 #include "courgette/base_test_unittest.h"
6
7 #include "base/path_service.h"
8 #include "base/file_util.h"
9 #include "base/string_util.h"
10
11 #include "courgette/courgette.h" 6 #include "courgette/courgette.h"
12 #include "courgette/streams.h" 7 #include "courgette/streams.h"
13 8
14 #include "testing/gtest/include/gtest/gtest.h" 9 class EncodeDecodeTest : public BaseTest {
15
16 class EncodeDecodeTest : public testing::Test {
17 public: 10 public:
18 void TestExe(const char *) const; 11 void TestExe(const char *) const;
19
20 private:
21 void SetUp() {
22 PathService::Get(base::DIR_SOURCE_ROOT, &testdata_dir_);
23 testdata_dir_ = testdata_dir_.AppendASCII("courgette");
24 testdata_dir_ = testdata_dir_.AppendASCII("testdata");
25 }
26
27 void TearDown() { }
28
29 // Returns contents of |file_name| as uninterprested bytes stored in a string.
30 std::string FileContents(const char* file_name) const;
31
32 FilePath testdata_dir_; // Full path name of testdata directory
33 }; 12 };
34 13
35 // Reads a test file into a string.
36 std::string EncodeDecodeTest::FileContents(const char* file_name) const {
37 FilePath file_path = testdata_dir_;
38 file_path = file_path.AppendASCII(file_name);
39 std::string file_contents;
40 if (!file_util::ReadFileToString(file_path, &file_contents)) {
41 EXPECT_TRUE(!"Could not read test data");
42 }
43 return file_contents;
44 }
45
46 void EncodeDecodeTest::TestExe(const char* file_name) const { 14 void EncodeDecodeTest::TestExe(const char* file_name) const {
47 // Test top-level Courgette API for converting an a file to a binary 15 // Test top-level Courgette API for converting an a file to a binary
48 // assembly representation and back. 16 // assembly representation and back.
49 std::string file1 = FileContents(file_name); 17 std::string file1 = FileContents(file_name);
50 18
51 const void* original_buffer = file1.c_str(); 19 const void* original_buffer = file1.c_str();
52 size_t original_length = file1.size(); 20 size_t original_length = file1.size();
53 21
54 courgette::AssemblyProgram* program = NULL; 22 courgette::AssemblyProgram* program = NULL;
55 const courgette::Status parse_status = 23 const courgette::Status parse_status =
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
96 EXPECT_EQ(original_length, assembled_length); 64 EXPECT_EQ(original_length, assembled_length);
97 EXPECT_EQ(0, memcmp(original_buffer, assembled_buffer, original_length)); 65 EXPECT_EQ(0, memcmp(original_buffer, assembled_buffer, original_length));
98 66
99 DeleteEncodedProgram(encoded2); 67 DeleteEncodedProgram(encoded2);
100 } 68 }
101 69
102 70
103 TEST_F(EncodeDecodeTest, All) { 71 TEST_F(EncodeDecodeTest, All) {
104 TestExe("setup1.exe"); 72 TestExe("setup1.exe");
105 } 73 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698