Skip to content
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

Merged
merged 15 commits into from
Oct 31, 2024

Conversation

illidanstormrange
Copy link
Collaborator

补充一些NativeCodec和DataView相关的单元测试

@illidanstormrange
Copy link
Collaborator Author

修复一下代码语法检查的错误

@illidanstormrange
Copy link
Collaborator Author

Fix code format check error

CHECK_PIXELS(A8Info, pixels, "NativeCodec_Encode_Alpha8");
}

TGFX_TEST(ImageReaderTest, DataCheck) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DataView不应该属于Image相关的测试,它是一个纯粹的二进制数据读写工具类,另外加个测试文件。

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

可以和其他工具类,比如UTF,Buffer, Clock,Stream这几个类放一起测试。

auto data = DataView(buffer.bytes(), buffer.size());
auto secondByte = data.getUint8(1);
auto thirdByte = data.getUint8(2);
auto fouthByte = data.getUint8(3);
Copy link
Collaborator

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

@illidanstormrange
Copy link
Collaborator Author

Add DataView unit Test, delete extra unit test in ReadPixelsTest

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);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

我们一般只在后续逻辑会出现空指针的时候才用ASERT,如果后续逻辑能正常运行,这里都用EXPECT_TRUE(),统一改一下吧

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

你随便用ASSERT会导致测试中断运行,一遍看不到具体多少个没通过。跑一次只能修一个问题。

auto unichar = UTF::NextUTF8(&textStart, textStop);
dataView.setInt32(offset, unichar);
}
ASSERT_EQ(std::string((char*)buffer.bytes()), text);
Copy link
Collaborator

@domchen domchen Oct 30, 2024

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所以通过了。容易内存访问越界报错。

@illidanstormrange
Copy link
Collaborator Author

修改一些不必要的Assert判断为Expect,初始化Buffer的数据为'\0'以免后面使用越界

@illidanstormrange
Copy link
Collaborator Author

修改Assert判断为Expect,string初始化时指定size,避免上面改变值时出现越界


TGFX_TEST(DataViewTest, ReadString) {
Buffer buffer(100);
memset(buffer.bytes(), 0, buffer.size());
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这句可以不要,或者用buffer.clear()

@illidanstormrange
Copy link
Collaborator Author

将一些不会导致程序崩溃的ASSERT条件,替换为使用EXPECT判断。Buffer初始化使用Clear()

@domchen domchen merged commit ad97733 into main Oct 31, 2024
8 checks passed
@domchen domchen deleted the feature/ljj_unit_test branch October 31, 2024 02:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants