开发者

Format for cross language common test data

开发者 https://www.devze.com 2023-04-01 18:23 出处:网络
I\'m currently working on the C++ side of a font library in both C++ and Java. We would like to generate test data from multiple fonts automatically and we\'re using 开发者_开发技巧Google Test and JU

I'm currently working on the C++ side of a font library in both C++ and Java.

We would like to generate test data from multiple fonts automatically and we're using 开发者_开发技巧Google Test and JUnit for testing.

I will write a script to generate the data in this common format that would then be parsed in tests. The thing is that for C++ I would also like to use Google Test's value-parameterized tests and that would mean having the data in C++ as well.

So, I'm thinking of outputting the data in some common format and having C++ files be generated from that.

Normally, we'd consider XML or JSON but Protocol Buffers seem to fit the bill of generating code very easily which makes them interesting. I've never used them and browsing through the documentation, they seem really good at defining messages, not so much storing actual values (so I can define a Person message, but what I really want to do is store a bunch of Person constants).

What format should we use?

Thanks!


It looks like Protocol Buffers is a good match for your use case. It is fast and easy to use in both C++ and Java environment. It is also very stable, well-documented and widely used outside Google.

As for storing multiple objects in a binary stream, there are well-known conventional methods for that. See, for example, this SO answer: Storing multiple messages in one protocol buffer binary file

Keep in mind that even though Protobuf is a binary format, it is still possible to convert your test cases to a human-readable format, such as JSON or XML. Here are some relevant links:

  • http://code.google.com/p/protobuf-java-format/
  • http://piqi.org/
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号