This source file includes following definitions.
- TEST
- TEST
#include "config.h"
#if ENABLE(OPENTYPE_VERTICAL)
#include <gtest/gtest.h>
#include "platform/SharedBuffer.h"
#include "platform/fonts/opentype/OpenTypeTypes.h"
#include "wtf/RefPtr.h"
using namespace WebCore;
namespace {
struct TestTable : OpenType::TableBase {
OpenType::Fixed version;
OpenType::Int16 ascender;
template <typename T> const T* validateOffset(const SharedBuffer& buffer, uint16_t offset) const
{
return TableBase::validateOffset<T>(buffer, offset);
}
};
TEST(OpenTypeVerticalDataTest, ValidateTableTest)
{
RefPtr<SharedBuffer> buffer = SharedBuffer::create(sizeof(TestTable));
const TestTable* table = OpenType::validateTable<TestTable>(buffer);
EXPECT_TRUE(table);
buffer = SharedBuffer::create(sizeof(TestTable) - 1);
table = OpenType::validateTable<TestTable>(buffer);
EXPECT_FALSE(table);
buffer = SharedBuffer::create(sizeof(TestTable) + 1);
table = OpenType::validateTable<TestTable>(buffer);
EXPECT_TRUE(table);
}
TEST(OpenTypeVerticalDataTest, ValidateOffsetTest)
{
RefPtr<SharedBuffer> buffer = SharedBuffer::create(sizeof(TestTable));
const TestTable* table = OpenType::validateTable<TestTable>(buffer);
ASSERT_TRUE(table);
EXPECT_FALSE(table->validateOffset<uint8_t>(*buffer, -1));
for (uint16_t offset = 0; offset < sizeof(TestTable); offset++)
EXPECT_TRUE(table->validateOffset<uint8_t>(*buffer, offset));
EXPECT_FALSE(table->validateOffset<uint8_t>(*buffer, sizeof(TestTable)));
EXPECT_FALSE(table->validateOffset<uint8_t>(*buffer, sizeof(TestTable) + 1));
for (uint16_t offset = 0; offset < sizeof(TestTable) - 1; offset++)
EXPECT_TRUE(table->validateOffset<uint16_t>(*buffer, offset));
EXPECT_FALSE(table->validateOffset<uint16_t>(*buffer, sizeof(TestTable) - 1));
}
}
#endif