summaryrefslogtreecommitdiffstats
path: root/src/base/test/utf8.cpp
diff options
context:
space:
mode:
authortpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2010-03-01 18:37:05 +0000
committertpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2010-03-01 18:37:05 +0000
commit145364a8af6a1fec06556221e66d4b724a62fc9a (patch)
tree53bd71a544008c518034f208d64c932dc2883f50 /src/base/test/utf8.cpp
downloadrosegarden-145364a8af6a1fec06556221e66d4b724a62fc9a.tar.gz
rosegarden-145364a8af6a1fec06556221e66d4b724a62fc9a.zip
Added old abandoned KDE3 version of the RoseGarden MIDI tool
git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/applications/rosegarden@1097595 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'src/base/test/utf8.cpp')
-rw-r--r--src/base/test/utf8.cpp96
1 files changed, 96 insertions, 0 deletions
diff --git a/src/base/test/utf8.cpp b/src/base/test/utf8.cpp
new file mode 100644
index 0000000..7104cc0
--- /dev/null
+++ b/src/base/test/utf8.cpp
@@ -0,0 +1,96 @@
+// -*- c-basic-offset: 4 -*-
+
+#include "XmlExportable.h"
+#include <iostream>
+#include <string>
+
+using namespace Rosegarden;
+using std::cout;
+using std::cerr;
+using std::endl;
+using std::string;
+
+
+string binary(unsigned char c)
+{
+ string s;
+ for (int i = 0; i < 8; ++i) {
+ s = ((c & 0x1) ? '1' : '0') + s;
+ c >>= 1;
+ }
+ return s;
+}
+
+
+int main(int argc, char **argv)
+{
+ string valid[] = {
+ "ニュース",
+ "주요 뉴스",
+ "Nyheter",
+ "天气",
+ "Notícias",
+ };
+
+ string escapable[] = {
+ "ニュ&ース",
+ "주요 <뉴스>",
+ "\"Nyheter\"",
+ "\'Notícias\'",
+ };
+
+ string invalid[] = {
+ "����ース",
+ "주� � 뉴스",
+ "Nyhe\004ter",
+ "�天气",
+ "Not�cias",
+ };
+
+ cout << "Testing valid strings -- should be no errors here" << endl;
+
+ for (int i = 0; i < sizeof(valid)/sizeof(valid[0]); ++i) {
+ string encoded = XmlExportable::encode(valid[i]);
+ if (encoded != valid[i]) {
+ cerr << "Encoding failed:" << endl;
+ for (int j = 0; j < valid[i].length(); ++j) {
+ cerr << (char)valid[i][j] << " ("
+ << binary(valid[i][j]) << ")" << endl;
+ }
+ exit(1);
+ }
+ }
+
+ cout << "Testing escapable strings -- should be no errors here" << endl;
+
+ for (int i = 0; i < sizeof(escapable)/sizeof(escapable[0]); ++i) {
+ string encoded = XmlExportable::encode(escapable[i]);
+ if (encoded == escapable[i]) {
+ cerr << "Escaping failed:" << endl;
+ for (int j = 0; j < escapable[i].length(); ++j) {
+ cerr << (char)escapable[i][j] << " ("
+ << binary(escapable[i][j]) << ")" << endl;
+ }
+ exit(1);
+ }
+ }
+
+ cout << "Testing invalid strings -- should be "
+ << (sizeof(invalid)/sizeof(invalid[0]))
+ << " errors here (but no fatal ones)" << endl;
+
+ for (int i = 0; i < sizeof(invalid)/sizeof(invalid[0]); ++i) {
+ string encoded = XmlExportable::encode(invalid[i]);
+ if (encoded == invalid[i]) {
+ cerr << "Encoding succeeded but should have failed:" << endl;
+ for (int j = 0; j < invalid[i].length(); ++j) {
+ cerr << (char)invalid[i][j] << " ("
+ << binary(invalid[i][j]) << ")" << endl;
+ }
+ exit(1);
+ }
+ }
+
+ exit(0);
+}
+