Index: import/cross/raw_data_test.cc |
=================================================================== |
--- import/cross/raw_data_test.cc (revision 20922) |
+++ import/cross/raw_data_test.cc (working copy) |
@@ -34,10 +34,17 @@ |
#include "core/cross/client.h" |
#include "tests/common/win/testing_common.h" |
+#include "utils/cross/file_path_utils.h" |
+#include "base/file_path.h" |
+#include "base/file_util.h" |
#include "core/cross/error.h" |
#include "import/cross/memory_buffer.h" |
#include "import/cross/raw_data.h" |
+using file_util::OpenFile; |
+using file_util::CloseFile; |
+using file_util::GetFileSize; |
+ |
namespace o3d { |
// Test fixture for RawData testing. |
@@ -75,6 +82,37 @@ |
ASSERT_EQ(raw_data->uri(), uri); |
} |
+TEST_F(RawDataTest, CreateFromFile) { |
+ String uri("test_filename"); |
+ String filename = *g_program_path + "/bitmap_test/tga-256x256-24bit.tga"; |
+ RawData::Ref ref = RawData::CreateFromFile(g_service_locator, |
+ uri, |
+ filename); |
+ ASSERT_FALSE(ref.IsNull()); |
+ FilePath filepath = UTF8ToFilePath(filename); |
+ FILE *file = OpenFile(filepath, "rb"); |
+ ASSERT_TRUE(file != NULL); |
+ int64 file_size64; |
+ ASSERT_TRUE(GetFileSize(filepath, &file_size64)); |
+ size_t file_length = static_cast<size_t>(file_size64); |
+ ASSERT_TRUE(file_length > 0); |
+ scoped_array<uint8> data(new uint8[file_length]); |
+ ASSERT_EQ(fread(data.get(), file_length, 1, file), 1); |
+ CloseFile(file); |
+ |
+ ASSERT_EQ(file_length, ref->GetLength()); |
+ ASSERT_EQ(0, memcmp(ref->GetData(), data.get(), file_length)); |
+} |
+ |
+TEST_F(RawDataTest, CreateFromFileFail) { |
+ String uri("test_filename"); |
+ String filename = *g_program_path + "/bitmap_test/non-existent-file.foo"; |
+ RawData::Ref ref = RawData::CreateFromFile(g_service_locator, |
+ uri, |
+ filename); |
+ ASSERT_TRUE(ref.IsNull()); |
+} |
+ |
namespace { |
struct TestData { |