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
This commit is contained in:
parent
62c6f56cbe
commit
e95c593cdc
1 changed files with 33 additions and 0 deletions
33
test_drivers/negative/negative.cpp
Normal file
33
test_drivers/negative/negative.cpp
Normal file
|
@ -0,0 +1,33 @@
|
|||
#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';
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue