// 2 2D blocks. // a a 0 b b // a a 0 b b void CComSuite::test_2d_separate() { writearray<10,uint8_t>(".rawfile", {{8,8,0,5,5,8,8,0,5,5}}); wrnhdr(5, 2, 1); ccom(".config"); std::ifstream outraw(".outraw", std::ios::binary); CPPUNIT_ASSERT(match<10>({{1,1,0,2,2,1,1,0,2,2}}, outraw)); CPPUNIT_ASSERT(at_eof(outraw)); }
// same value with a zero between it -- should become two separate components. void CComSuite::test_twovalues_separate() { writearray<7,uint8_t>(".rawfile", {{6,6,6,250,6,6,6}}); wrnhdr(7, 1, 1); ccom(".config"); std::ifstream outraw(".outraw", std::ios::binary); // make sure we get all the same value //debugout<7, uint8_t, uint32_t>(outraw); CPPUNIT_ASSERT(match<7>({{1,1,1,0,2,2,2}}, outraw)); // .. and also that the output is not too large. CPPUNIT_ASSERT(at_eof(outraw)); }
void CComSuite::test_empty() { std::ofstream empty(".rawfile", std::ios::binary); empty.close(); std::ofstream nhdr(".nhdr", std::ios::app); nhdr << "sizes: 0 0 0\n"; nhdr.close(); ccom(".config"); std::ifstream outraw(".outraw", std::ios::binary); CPPUNIT_ASSERT(outraw); uint8_t v; outraw.read(reinterpret_cast<char*>(&v), sizeof(uint8_t)); CPPUNIT_ASSERT(outraw.eof()); }
// two components but the range provided means they should be merged. void CComSuite::test_twovalues_merged() { writearray<6,uint8_t>(".rawfile", {{6,6, 19,19,19,19}}); std::ofstream nhdr(".nhdr", std::ios::app); nhdr << "sizes: 6 1 1\n"; nhdr.close(); ccom(".config"); std::ifstream outraw(".outraw", std::ios::binary); // make sure we get all the same value CPPUNIT_ASSERT(match<6>({{1,1,1,1,1,1}}, outraw)); // .. and also that the output is not too large. uint8_t v; outraw.read(reinterpret_cast<char*>(&v), sizeof(uint8_t)); CPPUNIT_ASSERT(outraw.eof()); }
// just a single value void CComSuite::test_single() { writearray<6,uint8_t>(".rawfile", {{19, 19, 19, 19, 19, 19}}); std::ofstream nhdr(".nhdr", std::ios::app); nhdr << "sizes: 6 1 1\n"; nhdr.close(); ccom(".config"); std::ifstream outraw(".outraw", std::ios::binary); // make sure we get all the same value uint8_t v; for(size_t i=0; i < 6; ++i) { outraw.read(reinterpret_cast<char*>(&v), sizeof(uint8_t)); CPPUNIT_ASSERT(v == 1); } // .. and also that the output is not too large. outraw.read(reinterpret_cast<char*>(&v), sizeof(uint8_t)); CPPUNIT_ASSERT(outraw.eof()); }
char csyntax( const char r) { char c, b; long row, col; while ( ( c = gc() ) != EOF ){ if (c == r) return r; row = crow; col = ccol; b = 0; // != EOF switch (c) { case '(': case '[': case '{': if ( (b = cnpairs( c )) != pair(c) ) err(row,col, "missing right", pair(c)); break; case ')': case ']': case '}': errc("missing left", pair(c)); break; case '\'': // Char ? if( ( b = cquotes('\'') ) != '\''){ err(row,col, "char constant missing right",'\''); } break; case '\"': // String ? if( ( b = cquotes('\"') ) != '\"'){ err(row,col, "string constant missing right",'\"'); } break; case '/': if ( (c = gc()) != EOF) { if ( c == '*') // Block comment ? { if( ( b = ccom('*') ) != '/'){ err(row,col, "bad block comment",' '); } }else if ( c=='/' ){ // Line comment ? if( ( b = ccom('/') ) != '\n'){ err(row,col, "bad line comment",' '); } }else{ err(row,col, "/ in text", ' '); return '/'; } }else { err(row,col, "/ before EOF", ' '); return EOF; } break; default: ; } if( b == EOF) return EOF; } return c; }