| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2009, Google Inc. | 2 * Copyright 2009, Google Inc. |
| 3 * All rights reserved. | 3 * All rights reserved. |
| 4 * | 4 * |
| 5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
| 6 * modification, are permitted provided that the following conditions are | 6 * modification, are permitted provided that the following conditions are |
| 7 * met: | 7 * met: |
| 8 * | 8 * |
| 9 * * Redistributions of source code must retain the above copyright | 9 * * Redistributions of source code must retain the above copyright |
| 10 * notice, this list of conditions and the following disclaimer. | 10 * notice, this list of conditions and the following disclaimer. |
| (...skipping 16 matching lines...) Expand all Loading... |
| 27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 29 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 29 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 30 */ | 30 */ |
| 31 | 31 |
| 32 | 32 |
| 33 // Tests functionality of the RawData class | 33 // Tests functionality of the RawData class |
| 34 | 34 |
| 35 #include "core/cross/client.h" | 35 #include "core/cross/client.h" |
| 36 #include "tests/common/win/testing_common.h" | 36 #include "tests/common/win/testing_common.h" |
| 37 #include "utils/cross/file_path_utils.h" |
| 38 #include "base/file_path.h" |
| 39 #include "base/file_util.h" |
| 37 #include "core/cross/error.h" | 40 #include "core/cross/error.h" |
| 38 #include "import/cross/memory_buffer.h" | 41 #include "import/cross/memory_buffer.h" |
| 39 #include "import/cross/raw_data.h" | 42 #include "import/cross/raw_data.h" |
| 40 | 43 |
| 44 using file_util::OpenFile; |
| 45 using file_util::CloseFile; |
| 46 using file_util::GetFileSize; |
| 47 |
| 41 namespace o3d { | 48 namespace o3d { |
| 42 | 49 |
| 43 // Test fixture for RawData testing. | 50 // Test fixture for RawData testing. |
| 44 class RawDataTest : public testing::Test { | 51 class RawDataTest : public testing::Test { |
| 45 }; | 52 }; |
| 46 | 53 |
| 47 // Test RawData | 54 // Test RawData |
| 48 TEST_F(RawDataTest, Basic) { | 55 TEST_F(RawDataTest, Basic) { |
| 49 String uri("test_filename"); | 56 String uri("test_filename"); |
| 50 const int kBufferLength = 1024; | 57 const int kBufferLength = 1024; |
| (...skipping 17 matching lines...) Expand all Loading... |
| 68 // Now, let's make sure it got the data length correct | 75 // Now, let's make sure it got the data length correct |
| 69 ASSERT_EQ(raw_data->GetLength(), buffer.GetLength()); | 76 ASSERT_EQ(raw_data->GetLength(), buffer.GetLength()); |
| 70 | 77 |
| 71 // Check the contents are correct | 78 // Check the contents are correct |
| 72 ASSERT_EQ(0, memcmp(raw_data->GetData(), buffer, buffer.GetLength())); | 79 ASSERT_EQ(0, memcmp(raw_data->GetData(), buffer, buffer.GetLength())); |
| 73 | 80 |
| 74 // Check that the uri is correct | 81 // Check that the uri is correct |
| 75 ASSERT_EQ(raw_data->uri(), uri); | 82 ASSERT_EQ(raw_data->uri(), uri); |
| 76 } | 83 } |
| 77 | 84 |
| 85 TEST_F(RawDataTest, CreateFromFile) { |
| 86 String uri("test_filename"); |
| 87 String filename = *g_program_path + "/bitmap_test/tga-256x256-24bit.tga"; |
| 88 RawData::Ref ref = RawData::CreateFromFile(g_service_locator, |
| 89 uri, |
| 90 filename); |
| 91 ASSERT_FALSE(ref.IsNull()); |
| 92 FilePath filepath = UTF8ToFilePath(filename); |
| 93 FILE *file = OpenFile(filepath, "rb"); |
| 94 ASSERT_TRUE(file != NULL); |
| 95 int64 file_size64; |
| 96 ASSERT_TRUE(GetFileSize(filepath, &file_size64)); |
| 97 size_t file_length = static_cast<size_t>(file_size64); |
| 98 ASSERT_TRUE(file_length > 0); |
| 99 scoped_array<uint8> data(new uint8[file_length]); |
| 100 ASSERT_EQ(fread(data.get(), file_length, 1, file), 1); |
| 101 CloseFile(file); |
| 102 |
| 103 ASSERT_EQ(file_length, ref->GetLength()); |
| 104 ASSERT_EQ(0, memcmp(ref->GetData(), data.get(), file_length)); |
| 105 } |
| 106 |
| 107 TEST_F(RawDataTest, CreateFromFileFail) { |
| 108 String uri("test_filename"); |
| 109 String filename = *g_program_path + "/bitmap_test/non-existent-file.foo"; |
| 110 RawData::Ref ref = RawData::CreateFromFile(g_service_locator, |
| 111 uri, |
| 112 filename); |
| 113 ASSERT_TRUE(ref.IsNull()); |
| 114 } |
| 115 |
| 78 namespace { | 116 namespace { |
| 79 | 117 |
| 80 struct TestData { | 118 struct TestData { |
| 81 const uint8* data; | 119 const uint8* data; |
| 82 size_t length; | 120 size_t length; |
| 83 bool valid; | 121 bool valid; |
| 84 size_t offset; | 122 size_t offset; |
| 85 }; | 123 }; |
| 86 | 124 |
| 87 } // anonymous namespace | 125 } // anonymous namespace |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 187 test_data.offset); | 225 test_data.offset); |
| 188 EXPECT_EQ(str.size(), test_length); | 226 EXPECT_EQ(str.size(), test_length); |
| 189 EXPECT_EQ(str.compare(0, test_length, test_string, test_length), 0); | 227 EXPECT_EQ(str.compare(0, test_length, test_string, test_length), 0); |
| 190 } else { | 228 } else { |
| 191 EXPECT_TRUE(str.empty()); | 229 EXPECT_TRUE(str.empty()); |
| 192 } | 230 } |
| 193 } | 231 } |
| 194 } | 232 } |
| 195 | 233 |
| 196 } // namespace o3d | 234 } // namespace o3d |
| OLD | NEW |