0

Is it possible to use google unit test to test table printing with c++?

Can that be done with other unit test framework?

So far, in A quick introduction to the Google C++ Testing Framework I only see test of values. This question at SO talks about using google mock to test arrays.

Community
  • 1
  • 1
rxu
  • 1,111
  • 1
  • 6
  • 24

1 Answers1

2

I would imagine you could use regex to check the format. C++11 has a function specifically for this. Below is an outlining example, adapted from cplusplus.com, but you could develop a more complex solution to test the table very exactly.

c++11

#include <string>
#include <regex>

std::string s = "|some|sort|of|table|row|"
std::regex r = "" // Matching regex
ASSERT_TRUE(std::regex_match(s, r))

Additionally, you could split (using std::string::find() and std::string::substr() as outlined here) the table to check individual values with something like ASSERT_EQ(parsed_value, exp_value)

Less Objective Comment:
I've found that google test has tools for pretty much everything. The value tests that you mentioned are actually extremely versatile. The (somewhat unavoidable) work is manipulating the data for the available tests, which means extrapolating the data and characteristics that you care about and presenting that to the ASSERT_* and EXPECT_* macros.

Community
  • 1
  • 1
rtmh
  • 439
  • 3
  • 9