Testgzbinstream.cpp 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. /*
  2. * NICE-Core - efficient algebra and computer vision methods
  3. * - libiocompression - An iocompression/template for new NICE libraries
  4. * See file License for license information.
  5. */
  6. #include "Testgzbinstream.h"
  7. #include <string>
  8. #include <vector>
  9. #include <exception>
  10. using namespace NICE;
  11. enum ENUM { ONE=1, TWO=2, FIVE=5 };
  12. CPPUNIT_TEST_SUITE_REGISTRATION( Testgzbinstream );
  13. void Testgzbinstream::setUp() {
  14. }
  15. void Testgzbinstream::tearDown() {
  16. remove("tmp.bgz");
  17. }
  18. void Testgzbinstream::testConstructor() {
  19. }
  20. void Testgzbinstream::testOperators() {
  21. #ifdef NICE_USELIB_ZLIB
  22. int i= rand();
  23. char c= rand();
  24. short s = rand();
  25. long l = rand();
  26. unsigned int ui = rand();
  27. unsigned short us = rand();
  28. unsigned char uc = rand();
  29. unsigned long ul = rand();
  30. float f = rand();
  31. double d = rand();
  32. long long ll = rand();
  33. unsigned long long ull = rand();
  34. long double ld = rand();
  35. ENUM enu=FIVE;
  36. std::vector<double> vd(10);
  37. for(uint i=0;i<vd.size();i++)
  38. vd[i]=i;
  39. std::vector<std::vector<std::string> > vvs(3);
  40. for(uint i=0;i<vvs.size();i++) {
  41. vvs[i].resize(3);
  42. for(int j=0;j<3;j++) {
  43. std::string x="test-";
  44. vvs[i][j]= x + (char)(i+'0')+(char)(j+'0');
  45. }
  46. }
  47. std::string str="string";
  48. ogzbinstream file("tmp.bgz");
  49. char array[]="array";
  50. file << 'x' << i << 'x' << c << 'x' << s << 'x' << l << 'x' << ll
  51. << 'x' << f << 'x' << d << 'x' << ld
  52. << 'x' << ui << 'x' << uc << 'x' << us << 'x' << ul << 'x' << ull
  53. << "array" << 'x' << str << 'x' << vd << 'x' << vvs << 'x'
  54. << (char)enu << 'x';
  55. ;
  56. file.close();
  57. int i_new= 0;
  58. char c_new= 0;
  59. short s_new= 0;
  60. long l_new= 0;
  61. unsigned int ui_new= 0;
  62. unsigned short us_new= 0;
  63. unsigned char uc_new= 0;
  64. unsigned long ul_new= 0;
  65. float f_new= 0;
  66. double d_new= 0;
  67. long long ll_new= 0;
  68. unsigned long long ull_new= 0;
  69. long double ld_new= 0;
  70. std::string str_new;
  71. char t[18];
  72. char buf[10];
  73. std::vector<double> vd_new;
  74. std::vector<std::vector<std::string> > vvs_new;
  75. ENUM enu_new;
  76. unsigned char enu_char;
  77. igzbinstream in("tmp.bgz");
  78. in >> t[0] >> i_new >> t[1] >> c_new >> t[2] >> s_new >> t[3] >> l_new >> t[4] >> ll_new
  79. >> t[5] >> f_new >> t[6] >> d_new >> t[7] >> ld_new
  80. >> t[8] >> ui_new >> t[9] >> uc_new >> t[10] >> us_new >> t[11] >> ul_new >> t[12] >> ull_new
  81. >> buf >> t[13] >> str_new >> t[14] >> vd_new >> t[15] >> vvs_new >>t[16] >> enu_char >> t[17];
  82. ;
  83. enu_new=(ENUM)enu_char;
  84. in.close();
  85. CPPUNIT_ASSERT_EQUAL(i, i_new);
  86. CPPUNIT_ASSERT_EQUAL(c, c_new);
  87. CPPUNIT_ASSERT_EQUAL(s, s_new);
  88. CPPUNIT_ASSERT_EQUAL(l, l_new);
  89. CPPUNIT_ASSERT_EQUAL(ll, ll_new);
  90. CPPUNIT_ASSERT_EQUAL(ui, ui_new);
  91. CPPUNIT_ASSERT_EQUAL(uc, uc_new);
  92. CPPUNIT_ASSERT_EQUAL(us, us_new);
  93. CPPUNIT_ASSERT_EQUAL(ul, ul_new);
  94. CPPUNIT_ASSERT_EQUAL(ull, ull_new);
  95. CPPUNIT_ASSERT_EQUAL(f, f_new);
  96. CPPUNIT_ASSERT_EQUAL(d, d_new);
  97. CPPUNIT_ASSERT_EQUAL(ld, ld_new);
  98. CPPUNIT_ASSERT_EQUAL(str, str_new);
  99. for(uint i=0;i<strlen(array);i++) {
  100. CPPUNIT_ASSERT_EQUAL(buf[i], array[i]);
  101. }
  102. for(uint i=0;i<vd.size();i++) {
  103. CPPUNIT_ASSERT_EQUAL(vd[i], vd_new[i]);
  104. }
  105. for(uint i=0;i<vvs.size();i++) {
  106. for(uint j=0;j<vvs[i].size();j++) {
  107. CPPUNIT_ASSERT_EQUAL(vvs[i][j], vvs_new[i][j]);
  108. }
  109. }
  110. CPPUNIT_ASSERT_EQUAL(enu, enu_new);
  111. for(int i=0;i<18;i++) {
  112. CPPUNIT_ASSERT_EQUAL(t[i], 'x');
  113. }
  114. #endif
  115. }