2020-06-13 12:06:54 +08:00
|
|
|
|
#include "gtest/gtest.h"
|
|
|
|
|
#include "tkc/data_reader_factory.h"
|
|
|
|
|
#include "base/data_reader_asset.h"
|
|
|
|
|
|
|
|
|
|
TEST(DataReaderAsset, basic) {
|
|
|
|
|
char data[256];
|
2020-06-26 16:55:16 +08:00
|
|
|
|
uint32_t size = 0;
|
2020-06-13 12:06:54 +08:00
|
|
|
|
data_reader_t* reader = NULL;
|
|
|
|
|
data_reader_factory_t* f = data_reader_factory_create();
|
|
|
|
|
|
|
|
|
|
ASSERT_EQ(data_reader_factory_register(f, "asset", data_reader_asset_create), RET_OK);
|
|
|
|
|
|
|
|
|
|
reader = data_reader_factory_create_reader(f, "asset://test.json");
|
|
|
|
|
ASSERT_EQ(reader != NULL, true);
|
|
|
|
|
|
|
|
|
|
memset(data, 0x00, sizeof(data));
|
2020-06-26 16:55:16 +08:00
|
|
|
|
size = data_reader_get_size(reader);
|
|
|
|
|
ASSERT_EQ(size >= 24, true);
|
|
|
|
|
ASSERT_EQ(data_reader_read(reader, 0, data, sizeof(data)), size);
|
2020-06-13 12:06:54 +08:00
|
|
|
|
|
|
|
|
|
data_reader_destroy(reader);
|
|
|
|
|
data_reader_factory_destroy(f);
|
|
|
|
|
}
|
2020-12-22 14:13:24 +08:00
|
|
|
|
|
|
|
|
|
TEST(DataReaderAsset, data) {
|
|
|
|
|
char data[256];
|
|
|
|
|
uint32_t size = 0;
|
2020-12-29 17:54:57 +08:00
|
|
|
|
char url[MAX_PATH + 1];
|
2020-12-22 14:13:24 +08:00
|
|
|
|
data_reader_t* reader = NULL;
|
|
|
|
|
data_reader_factory_t* f = data_reader_factory_create();
|
|
|
|
|
|
|
|
|
|
ASSERT_EQ(data_reader_factory_register(f, "asset", data_reader_asset_create), RET_OK);
|
|
|
|
|
|
2020-12-23 15:55:57 +08:00
|
|
|
|
data_reader_asset_build_url("test.json", ASSET_TYPE_DATA, url);
|
|
|
|
|
reader = data_reader_factory_create_reader(f, url);
|
2020-12-22 14:13:24 +08:00
|
|
|
|
ASSERT_EQ(reader != NULL, true);
|
|
|
|
|
|
|
|
|
|
memset(data, 0x00, sizeof(data));
|
|
|
|
|
size = data_reader_get_size(reader);
|
|
|
|
|
ASSERT_EQ(size >= 24, true);
|
|
|
|
|
ASSERT_EQ(data_reader_read(reader, 0, data, sizeof(data)), size);
|
|
|
|
|
|
|
|
|
|
data_reader_destroy(reader);
|
|
|
|
|
data_reader_factory_destroy(f);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST(DataReaderAsset, ui) {
|
|
|
|
|
char data[32];
|
|
|
|
|
uint32_t size = 0;
|
2020-12-29 17:54:57 +08:00
|
|
|
|
char url[MAX_PATH + 1];
|
2020-12-22 14:13:24 +08:00
|
|
|
|
data_reader_t* reader = NULL;
|
|
|
|
|
data_reader_factory_t* f = data_reader_factory_create();
|
|
|
|
|
|
|
|
|
|
ASSERT_EQ(data_reader_factory_register(f, "asset", data_reader_asset_create), RET_OK);
|
|
|
|
|
|
2020-12-23 15:55:57 +08:00
|
|
|
|
data_reader_asset_build_url("main", ASSET_TYPE_UI, url);
|
|
|
|
|
reader = data_reader_factory_create_reader(f, url);
|
2020-12-22 14:13:24 +08:00
|
|
|
|
ASSERT_EQ(reader != NULL, true);
|
|
|
|
|
|
|
|
|
|
memset(data, 0x00, sizeof(data));
|
|
|
|
|
size = data_reader_get_size(reader);
|
|
|
|
|
ASSERT_EQ(size >= 24, true);
|
|
|
|
|
ASSERT_EQ(data_reader_read(reader, 0, data, sizeof(data)), sizeof(data));
|
|
|
|
|
|
|
|
|
|
data_reader_destroy(reader);
|
|
|
|
|
data_reader_factory_destroy(f);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST(DataReaderAsset, style) {
|
|
|
|
|
char data[32];
|
|
|
|
|
uint32_t size = 0;
|
2020-12-29 17:54:57 +08:00
|
|
|
|
char url[MAX_PATH + 1];
|
2020-12-22 14:13:24 +08:00
|
|
|
|
data_reader_t* reader = NULL;
|
|
|
|
|
data_reader_factory_t* f = data_reader_factory_create();
|
|
|
|
|
|
|
|
|
|
ASSERT_EQ(data_reader_factory_register(f, "asset", data_reader_asset_create), RET_OK);
|
|
|
|
|
|
2020-12-23 15:55:57 +08:00
|
|
|
|
data_reader_asset_build_url("default", ASSET_TYPE_STYLE, url);
|
|
|
|
|
reader = data_reader_factory_create_reader(f, url);
|
2020-12-22 14:13:24 +08:00
|
|
|
|
ASSERT_EQ(reader != NULL, true);
|
|
|
|
|
|
|
|
|
|
memset(data, 0x00, sizeof(data));
|
|
|
|
|
size = data_reader_get_size(reader);
|
|
|
|
|
ASSERT_EQ(size >= 24, true);
|
|
|
|
|
ASSERT_EQ(data_reader_read(reader, 0, data, sizeof(data)), sizeof(data));
|
|
|
|
|
|
|
|
|
|
data_reader_destroy(reader);
|
|
|
|
|
data_reader_factory_destroy(f);
|
|
|
|
|
}
|