9 #include <boost/test/tools/output_test_stream.hpp> 
   10 #include <boost/test/unit_test.hpp> 
   20 using boost::test_tools::output_test_stream;
 
   25 BOOST_AUTO_TEST_SUITE(Visualization)
 
   29   std::string validObj = R
"(# obj test file
mtllib material.mtl
usemtl material_a
g rectangle
vn 0 0 1
vt 0 0 1
v -15 -15 0
v 15 -15 0
v 15 15 0
v -15 15 0
f 1 2 3 4
l 1 2
l 2 3
l 3 4
l 4 1
)"; 
   33   BOOST_CHECK(objErrors.size() == 0);
 
   37   BOOST_CHECK(objErrors.size() == 1);
 
   38   for (
auto objerr : objErrors) {
 
   39     std::cout << objerr << std::endl;
 
   43   std::string invalidObj = R
"(# obj test file
mtllib material.mtl
usemtl material_a
x whatever
g rectangle
vn 0 0 1
vt 0 0 1
v -15 -15 0 23
v 15 -15 0
v 15. 15 0
v -15 15. 0
f 1 2 3. 4
l 0 2
l 2 3
l 3 4
l 4 1
)"; 
   46   BOOST_CHECK(objErrors.size() == 4); 
   47   for (
auto objerr : objErrors) {
 
   48     std::cout << objerr << std::endl;
 
   54   std::string validPly = R
"(ply
format ascii 1.0    
comment made by Greg Turk
comment this file is a cube
element vertex 8
property float x
property float y
property float z
element face 6
property list uchar int vertex_indices
end_header
0 0 0
0 0 1
0 1 1
0 1 0
1 0 0
1 0 1
1 1 1
1 1 0
4 0 1 2 3
4 7 6 5 4
4 0 4 5 1
4 1 5 6 2
4 2 6 7 3
4 3 7 4 0
)"; 
   58   BOOST_CHECK(plyErrors.size() == 0);
 
   62   BOOST_CHECK(plyErrors.size() == 0);
 
   63   for (
auto plyerr : plyErrors) {
 
   64     std::cout << plyerr << std::endl;
 
   68   std::string invalidPly = R
"(ply
format ascii 1.0    
comment made by Greg Turk
comment this file is a cube
element vertex 8
property float x
property float y
property float z
element face 6
property list uchar int vertex_indices
whatever i write here
end_header
0 0 0 0
0 0 1
0 1 1
0 1 0
1 0 0
1 0 1
1 1 1
1 1 0
4 0 1 2 3
4 7 6 5 4
4 0 4 5 1
4 1 5 6
4 2 6 7 3
4 3 7 4 0
)"; 
   72   BOOST_CHECK(plyErrors.size() == 3);
 
   73   for (
auto plyerr : plyErrors) {
 
   74     std::cout << plyerr << std::endl;
 
   86   std::cout << *vis << std::endl;
 
   88   std::cout << *vis << std::endl;
 
   93   output_test_stream output;
 
   97   std::string exp = R
"(ply
format ascii 1.0
element vertex 1
property float x
property float y
property float z
property uchar red
property uchar green
property uchar blue
element face 0
property list uchar int vertex_index
element edge 0
property int vertex1
property int vertex2
property uchar red
property uchar green
property uchar blue
end_header
0 0 0 120 120 120
)"; 
  100   BOOST_CHECK(output.is_equal(exp)); 
  103   ply.vertex({0, 1, 0}); 
  105   exp = R"(ply
format ascii 1.0
element vertex 1
property float x
property float y
property float z
property uchar red
property uchar green
property uchar blue
element face 0
property list uchar int vertex_index
element edge 0
property int vertex1
property int vertex2
property uchar red
property uchar green
property uchar blue
end_header
0 1 0 120 120 120
)"; 
  108   BOOST_CHECK(output.is_equal(exp)); 
  111   ply.line({0, 0, 1}, {1, 0, 0}); 
  115   exp = R"(ply
format ascii 1.0
element vertex 2
property float x
property float y
property float z
property uchar red
property uchar green
property uchar blue
element face 0
property list uchar int vertex_index
element edge 1
property int vertex1
property int vertex2
property uchar red
property uchar green
property uchar blue
end_header
0 0 1 120 120 120
1 0 0 120 120 120
0 1 120 120 120
)"; 
  117   BOOST_CHECK(output.is_equal(exp)); 
  120   ply.face({{1, 0, 0}, {1, 1, 0}, {0, 1, 0}}); 
  124   exp = R"(ply
format ascii 1.0
element vertex 3
property float x
property float y
property float z
property uchar red
property uchar green
property uchar blue
element face 1
property list uchar int vertex_index
element edge 0
property int vertex1
property int vertex2
property uchar red
property uchar green
property uchar blue
end_header
1 0 0 120 120 120
1 1 0 120 120 120
0 1 0 120 120 120
3 0 1 2
)"; 
  126   BOOST_CHECK(output.is_equal(exp)); 
  130   ObjVisualization obj; 
  132   output_test_stream output; 
  134   obj.vertex({1, 0, 0}); 
  138   std::string exp = R"(v 1 0 0
)"; 
  140   BOOST_CHECK(output.is_equal(exp)); 
  143   obj.face({{1, 0, 0}, {1, 1, 0}, {0, 1, 0}}); 
  146   exp = R"(v 1 0 0
v 1 1 0
v 0 1 0
f 1 2 3
)"; 
  148   BOOST_CHECK(output.is_equal(exp)); 
  151 BOOST_AUTO_TEST_SUITE_END()