test/java_string: replace tabs with spaces, fix how tiny_utf8::string is being instantiated
parent
e184acde00
commit
34e30c0bd4
|
@ -23,48 +23,61 @@
|
||||||
|
|
||||||
int main(){
|
int main(){
|
||||||
|
|
||||||
|
// metadata for things in resources/unicode_data/
|
||||||
|
// normal_utf-8: 116 bytes, 85 characters ??
|
||||||
|
// java-style_unicode: 119 bytes, 85 characters ??
|
||||||
|
|
||||||
std::cout << "################################################################################" << std::endl;
|
std::cout << "################################################################################" << std::endl;
|
||||||
std::cout << "Java String Tests" << std::endl;
|
std::cout << "Java String Tests" << std::endl;
|
||||||
std::cout << "################################################################################" << std::endl;
|
std::cout << "################################################################################" << std::endl;
|
||||||
|
|
||||||
|
char* nextChar = new char;
|
||||||
|
|
||||||
std::streampos javaSize;
|
std::streampos javaSize;
|
||||||
char* javaData;
|
std::string javaStdString;
|
||||||
std::ifstream javaFile("./resources/unicode_data/java-style_unicode", std::ios::in | std::ios::binary | std::ios::ate);
|
const char* javaFilePath = "./resources/unicode_data/java-style_unicode";
|
||||||
|
std::ifstream javaFile(javaFilePath, std::ios::in | std::ios::binary | std::ios::ate);
|
||||||
if(javaFile.is_open()){
|
if(javaFile.is_open()){
|
||||||
javaSize = javaFile.tellg();
|
javaSize = javaFile.tellg();
|
||||||
javaData = new char[javaSize];
|
|
||||||
javaFile.seekg(0, std::ios::beg);
|
javaFile.seekg(0, std::ios::beg);
|
||||||
javaFile.read(javaData, javaSize);
|
|
||||||
javaFile.close();
|
for (int i=0; i<javaSize; i++) {
|
||||||
|
javaFile.read(nextChar, 1);
|
||||||
|
javaStdString.push_back(*nextChar);
|
||||||
}
|
}
|
||||||
|
|
||||||
tiny_utf8::string importString = JavaCompat::importJavaFormatToString((uint8_t*) javaData);
|
javaFile.close();
|
||||||
|
} else {
|
||||||
|
std::cerr << "Failed to open file: " << javaFilePath << std::endl;
|
||||||
|
return 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
tiny_utf8::string importedString = JavaCompat::importJavaFormat(reinterpret_cast<uint8_t*>(javaStdString.data()));
|
||||||
|
|
||||||
std::streampos normalSize;
|
std::streampos normalSize;
|
||||||
char* normalData;
|
std::string normalStdString;
|
||||||
std::ifstream normalFile("./resources/unicode_data/normal_utf-8", std::ios::in | std::ios::binary | std::ios::ate);
|
const char* normalFilePath = "./resources/unicode_data/normal_utf-8";
|
||||||
|
std::ifstream normalFile(normalFilePath, std::ios::in | std::ios::binary | std::ios::ate);
|
||||||
if(normalFile.is_open()){
|
if(normalFile.is_open()){
|
||||||
normalSize = normalFile.tellg();
|
normalSize = normalFile.tellg();
|
||||||
normalData = new char[normalSize];
|
|
||||||
normalFile.seekg(0, std::ios::beg);
|
normalFile.seekg(0, std::ios::beg);
|
||||||
normalFile.read(normalData, normalSize);
|
|
||||||
|
for (int i=0; i<normalSize; i++) {
|
||||||
|
normalFile.read(nextChar, 1);
|
||||||
|
normalStdString.push_back(*nextChar);
|
||||||
|
}
|
||||||
|
|
||||||
normalFile.close();
|
normalFile.close();
|
||||||
|
} else {
|
||||||
|
std::cerr << "Failed to open file: " << normalFilePath << std::endl;
|
||||||
|
return 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<char> normalDataVector = std::vector<char>();
|
tiny_utf8::string normalString = tiny_utf8::string(normalStdString);
|
||||||
for(int i=0; i<normalSize; i++){
|
|
||||||
normalDataVector.push_back(normalData[i]);
|
|
||||||
}
|
|
||||||
|
|
||||||
tiny_utf8::string normalString = tiny_utf8::string(normalDataVector.begin(), normalDataVector.end());
|
ASSERT(normalString == importedString);
|
||||||
|
|
||||||
std::cout << normalString.size() << std::endl;
|
|
||||||
std::cout << importString.size() << std::endl;
|
|
||||||
|
|
||||||
ASSERT(normalString == importString);
|
|
||||||
std::cout << "Passed Import Java string test." << std::endl;
|
std::cout << "Passed Import Java string test." << std::endl;
|
||||||
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue