1 // This is core/vnl/io/tests/test_sym_matrix_io.cxx
2 #include <iostream>
3 #include "vnl/vnl_sym_matrix.h"
4 #include <vnl/io/vnl_io_sym_matrix.h>
5 #include "testlib/testlib_test.h"
6 #include "vpl/vpl.h"
7 
8 void
test_sym_matrix_double_io()9 test_sym_matrix_double_io()
10 {
11   std::cout << "*********************************\n"
12             << "Testing vnl_sym_matrix<double> io\n"
13             << "*********************************\n";
14   //// test constructors, accessors
15   constexpr int n = 6;
16   vnl_sym_matrix<double> m_out(n), m_in1(n), m_in2;
17 
18   for (int i = 0; i < n; i++)
19   {
20     for (int j = 0; j <= i; j++)
21     {
22       m_out(i, j) = (double)(i * j);
23       m_in1(i, j) = (double)(73);
24     }
25   }
26 
27 
28   vsl_b_ofstream bfs_out("vnl_sym_matrix_test_double_io.bvl.tmp");
29   TEST("Created vnl_sym_matrix_test_double_io.bvl.tmp for writing", (!bfs_out), false);
30   vsl_b_write(bfs_out, m_out);
31   vsl_b_write(bfs_out, m_out);
32   bfs_out.close();
33 
34   vsl_b_ifstream bfs_in("vnl_sym_matrix_test_double_io.bvl.tmp");
35   TEST("Opened vnl_sym_matrix_test_double_io.bvl.tmp for reading", (!bfs_in), false);
36   vsl_b_read(bfs_in, m_in1);
37   vsl_b_read(bfs_in, m_in2);
38   TEST("Finished reading file successfully", (!bfs_in), false);
39   bfs_in.close();
40 
41   vpl_unlink("vnl_sym_matrix_test_double_io.bvl.tmp");
42 
43   // m_in1 has content
44   TEST("m_out == m_in1", m_out, m_in1);
45   // m_in2 empty
46   TEST("m_out == m_in2", m_out, m_in2);
47 
48   vsl_print_summary(std::cout, m_out);
49   std::cout << std::endl;
50 }
51 
52 
53 void
test_sym_matrix_io()54 test_sym_matrix_io()
55 {
56   test_sym_matrix_double_io();
57 }
58 
59 
60 TESTMAIN(test_sym_matrix_io);
61