utfcpp/test_drivers/negative/negative.cpp
ntrifunovic e95c593cdc Added "negative test driver" - a short program that displayes lines from utf8_invalid.txt that
contain invalid utf-8 sequences


git-svn-id: http://svn.code.sf.net/p/utfcpp/code@4 a809a056-fc17-0410-9590-b4f493f8b08e
2006-07-12 12:49:06 +00:00

33 lines
768 B
C++

#include "../../source/utf8.h"
using namespace utf8;
#include <string>
#include <iostream>
#include <fstream>
using namespace std;
const char* TEST_FILE_PATH = "../../test_data/negative/utf8_invalid.txt";
int main()
{
// Open the test file
ifstream fs8(TEST_FILE_PATH);
if (!fs8.is_open()) {
cout << "Could not open " << TEST_FILE_PATH << endl;
return 0;
}
// Read it line by line
unsigned int line_count = 0;
char byte;
while (!fs8.eof()) {
string line;
while ((byte = fs8.get()) != '\n' && !fs8.eof())
line.push_back(byte);
line_count++;
// Print out lines that contain invalid UTF-8
if (!is_valid(line.begin(), line.end()))
cout << line_count << ": " << line << '\n';
}
}