-
Notifications
You must be signed in to change notification settings - Fork 72
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add some unit tests related to NativeCodec and DataView. #285
Conversation
修复一下代码语法检查的错误 |
Fix code format check error |
test/src/ReadPixelsTest.cpp
Outdated
CHECK_PIXELS(A8Info, pixels, "NativeCodec_Encode_Alpha8"); | ||
} | ||
|
||
TGFX_TEST(ImageReaderTest, DataCheck) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
DataView不应该属于Image相关的测试,它是一个纯粹的二进制数据读写工具类,另外加个测试文件。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
可以和其他工具类,比如UTF,Buffer, Clock,Stream这几个类放一起测试。
test/src/ReadPixelsTest.cpp
Outdated
auto data = DataView(buffer.bytes(), buffer.size()); | ||
auto secondByte = data.getUint8(1); | ||
auto thirdByte = data.getUint8(2); | ||
auto fouthByte = data.getUint8(3); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里DataView的公开接口也没有覆盖全,读写int16, int32,int64, float 等等,还要区分ByteOrder::LittleEndian 和BigEndian
Add DataView unit Test, delete extra unit test in ReadPixelsTest |
test/src/DataViewTest.cpp
Outdated
Stream::MakeFromFile(ProjectPath::Absolute("resources/apitest/test_timestretch.png")); | ||
ASSERT_TRUE(stream != nullptr && stream->size() >= 14); | ||
Buffer buffer(14); | ||
ASSERT_TRUE(stream->read(buffer.data(), 14) == 14); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
我们一般只在后续逻辑会出现空指针的时候才用ASERT,如果后续逻辑能正常运行,这里都用EXPECT_TRUE(),统一改一下吧
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
你随便用ASSERT会导致测试中断运行,一遍看不到具体多少个没通过。跑一次只能修一个问题。
test/src/DataViewTest.cpp
Outdated
auto unichar = UTF::NextUTF8(&textStart, textStop); | ||
dataView.setInt32(offset, unichar); | ||
} | ||
ASSERT_EQ(std::string((char*)buffer.bytes()), text); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
std::string()要加上第二个参数size,否则你要再文本结束的地方后面一个字符加个0,现在只是内存刚好是0所以通过了。容易内存访问越界报错。
修改一些不必要的Assert判断为Expect,初始化Buffer的数据为'\0'以免后面使用越界 |
修改Assert判断为Expect,string初始化时指定size,避免上面改变值时出现越界 |
test/src/DataViewTest.cpp
Outdated
|
||
TGFX_TEST(DataViewTest, ReadString) { | ||
Buffer buffer(100); | ||
memset(buffer.bytes(), 0, buffer.size()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这句可以不要,或者用buffer.clear()
将一些不会导致程序崩溃的ASSERT条件,替换为使用EXPECT判断。Buffer初始化使用Clear() |
补充一些NativeCodec和DataView相关的单元测试