| OLD | NEW |
| (Empty) |
| 1 // Copyright 2009 Google Inc. | |
| 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 | |
| 16 #include "omaha/mi_exe_stub/x86_encoder/bcj2_encoder.h" | |
| 17 #include <string> | |
| 18 #include <vector> | |
| 19 #include "omaha/base/utils.h" | |
| 20 #include "omaha/testing/unit_test.h" | |
| 21 extern "C" { | |
| 22 #include "omaha/third_party/lzma/v4_65/files/C/Bcj2.h" | |
| 23 } | |
| 24 | |
| 25 namespace omaha { | |
| 26 | |
| 27 TEST(Bcj2EncoderTest, EmptyBuffer) { | |
| 28 std::string input; | |
| 29 std::string output1; | |
| 30 std::string output2; | |
| 31 std::string output3; | |
| 32 std::string output4; | |
| 33 ASSERT_TRUE(Bcj2Encode(input, &output1, &output2, &output3, &output4)); | |
| 34 EXPECT_EQ("", output1); | |
| 35 EXPECT_EQ("", output2); | |
| 36 EXPECT_EQ("", output3); | |
| 37 EXPECT_EQ(std::string(5, '\0'), output4); | |
| 38 } | |
| 39 | |
| 40 // Test that the transform is reversible. | |
| 41 TEST(Bcj2EncoderTest, Reversible) { | |
| 42 // The victim program is the unit test itself. | |
| 43 WCHAR module_path[MAX_PATH]; | |
| 44 ASSERT_LT(static_cast<DWORD>(0), ::GetModuleFileName(NULL, | |
| 45 module_path, | |
| 46 arraysize(module_path))); | |
| 47 std::vector<byte> raw_file; | |
| 48 ASSERT_HRESULT_SUCCEEDED( | |
| 49 ReadEntireFileShareMode(module_path, 0, FILE_SHARE_READ, &raw_file)); | |
| 50 const std::string input(reinterpret_cast<char*>(&raw_file[0]), | |
| 51 raw_file.size()); | |
| 52 std::string output1; | |
| 53 std::string output2; | |
| 54 std::string output3; | |
| 55 std::string output4; | |
| 56 ASSERT_TRUE(Bcj2Encode(input, &output1, &output2, &output3, &output4)); | |
| 57 | |
| 58 std::string decoded_output; | |
| 59 decoded_output.resize(raw_file.size()); | |
| 60 ASSERT_EQ(SZ_OK, Bcj2_Decode(reinterpret_cast<const uint8*>(output1.data()), | |
| 61 output1.size(), | |
| 62 reinterpret_cast<const uint8*>(output2.data()), | |
| 63 output2.size(), | |
| 64 reinterpret_cast<const uint8*>(output3.data()), | |
| 65 output2.size(), | |
| 66 reinterpret_cast<const uint8*>(output4.data()), | |
| 67 output4.size(), | |
| 68 reinterpret_cast<uint8*>(&decoded_output[0]), | |
| 69 decoded_output.size())); | |
| 70 EXPECT_EQ(input, decoded_output); | |
| 71 } | |
| 72 | |
| 73 } // namespace omaha | |
| OLD | NEW |