eliot-dev
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Eliot-dev] eliot/qt main_window.cpp qtcommon.cpp qtcommon.h


From: Olivier Teulière
Subject: [Eliot-dev] eliot/qt main_window.cpp qtcommon.cpp qtcommon.h
Date: Sat, 30 Jul 2011 19:49:29 +0000

CVSROOT:        /cvsroot/eliot
Module name:    eliot
Changes by:     Olivier Teulière <ipkiss>       11/07/30 19:49:29

Modified files:
        qt             : main_window.cpp qtcommon.cpp qtcommon.h 

Log message:
        Added a unit test for all the string conversions

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/eliot/qt/main_window.cpp?cvsroot=eliot&r1=1.43&r2=1.44
http://cvs.savannah.gnu.org/viewcvs/eliot/qt/qtcommon.cpp?cvsroot=eliot&r1=1.2&r2=1.3
http://cvs.savannah.gnu.org/viewcvs/eliot/qt/qtcommon.h?cvsroot=eliot&r1=1.12&r2=1.13

Patches:
Index: main_window.cpp
===================================================================
RCS file: /cvsroot/eliot/eliot/qt/main_window.cpp,v
retrieving revision 1.43
retrieving revision 1.44
diff -u -b -r1.43 -r1.44
--- main_window.cpp     30 Jul 2011 19:45:19 -0000      1.43
+++ main_window.cpp     30 Jul 2011 19:49:29 -0000      1.44
@@ -71,6 +71,11 @@
     m_prefsDialog(NULL), m_bagWindow(NULL), m_boardWindow(NULL),
     m_historyWindow(NULL), m_dicToolsWindow(NULL), m_dicNameLabel(NULL)
 {
+#ifdef DEBUG
+    // Check that the string conversion routines are not buggy
+    checkConversions();
+#endif
+
     LOG_DEBUG("Creating main window");
     m_ui.setupUi(this);
     createMenu();

Index: qtcommon.cpp
===================================================================
RCS file: /cvsroot/eliot/eliot/qt/qtcommon.cpp,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -b -r1.2 -r1.3
--- qtcommon.cpp        30 Jul 2011 19:45:19 -0000      1.2
+++ qtcommon.cpp        30 Jul 2011 19:49:29 -0000      1.3
@@ -1,7 +1,7 @@
 /*****************************************************************************
  * Eliot
- * Copyright (C) 2010 Olivier Teulière
- * Authors: Olivier Teulière <ipkiss @@ gmail.com>
+ * Copyright (C) 2010-2011 Olivier Teulière
+ * Authors: Olivier Teulière <ipkiss @@ gmail.com>
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -19,6 +19,7 @@
  *****************************************************************************/
 
 #include "qtcommon.h"
+#include <iostream>
 
 using namespace std;
 
@@ -46,3 +47,57 @@
 #endif
 }
 
+static void logFailedTest(const string &testName)
+{
+    cerr << "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@" << endl;
+    cerr << "@@@@@@@ Test " + testName + " failed! @@@@@@@" << endl;
+    cerr << "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@" << endl << endl;
+}
+
+void checkConversions()
+{
+    string s = "abcdéöùßĿ";
+
+    // Check identities
+    if (s != lfw(wfl(s)))
+        logFailedTest("1");
+    if (s != lfu(ufl(s)))
+        logFailedTest("2");
+    if (s != lfq(qfl(s)))
+        logFailedTest("3");
+
+    wstring w = wfl(s);
+    if (w != wfl(lfw(w)))
+        logFailedTest("4");
+    if (w != wfu(ufw(w)))
+        logFailedTest("5");
+    if (w != wfq(qfw(w)))
+        logFailedTest("6");
+
+    QString q = qfl(s);
+    if (q != qfl(lfq(q)))
+        logFailedTest("7");
+    if (q != qfu(ufq(q)))
+        logFailedTest("8");
+    if (q != qfw(wfq(q)))
+        logFailedTest("9");
+
+    // Check some cycles
+    if (s != lfu(ufw(wfl(s))))
+        logFailedTest("10");
+    if (s != lfw(wfu(ufl(s))))
+        logFailedTest("11");
+    if (s != lfq(qfw(wfl(s))))
+        logFailedTest("12");
+    if (s != lfw(wfq(qfl(s))))
+        logFailedTest("13");
+    if (s != lfu(ufw(wfq(qfl(s)))))
+        logFailedTest("14");
+    if (s != lfq(qfw(wfu(ufl(s)))))
+        logFailedTest("15");
+    if (s != lfu(ufq(qfw(wfl(s)))))
+        logFailedTest("16");
+    if (s != lfw(wfq(qfu(ufl(s)))))
+        logFailedTest("17");
+}
+

Index: qtcommon.h
===================================================================
RCS file: /cvsroot/eliot/eliot/qt/qtcommon.h,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -b -r1.12 -r1.13
--- qtcommon.h  30 Jul 2011 19:45:19 -0000      1.12
+++ qtcommon.h  30 Jul 2011 19:49:29 -0000      1.13
@@ -1,6 +1,6 @@
 /*****************************************************************************
  * Eliot
- * Copyright (C) 2010 Olivier Teulière
+ * Copyright (C) 2010-2011 Olivier Teulière
  * Authors: Olivier Teulière <ipkiss @@ gmail.com>
  *
  * This program is free software; you can redistribute it and/or modify
@@ -43,7 +43,7 @@
 #define qfl(s) qfw(convertToWc(s))
 #define lfq(s) convertToMb(wfq(s))
 // Convert to/from utf-8 char*
-#define qfu(s) QString::fromUtf8(s)
+#define qfu(s) QString::fromUtf8(string(s).c_str())
 #define ufq(s) (s).toUtf8().data()
 // Translation macro to use gettext
 #ifdef __APPLE__
@@ -58,4 +58,7 @@
 // Used for QSettings
 #define ORGANIZATION "eliot"
 
+// Unit test for the macros above
+void checkConversions();
+
 #endif



reply via email to

[Prev in Thread] Current Thread [Next in Thread]