From e43778b08b3af53080be2688836c41d32795f2df Mon Sep 17 00:00:00 2001 From: "T. van der Zwan" Date: Fri, 22 Nov 2013 10:44:41 +0000 Subject: [PATCH] Added small test to parse some parts of the json file Former-commit-id: 2ecdb7d12289d63a5fde051262162d01d768c328 --- test/CMakeLists.txt | 4 ++++ test/TestQRegExp.cpp | 50 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+) create mode 100644 test/TestQRegExp.cpp diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 5e2844e3..22957155 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -41,5 +41,9 @@ add_executable(test_blackborderprocessor target_link_libraries(test_blackborderprocessor hyperion) +add_executable(test_qregexp TestQRegExp.cpp) +target_link_libraries(test_qregexp + ${QT_LIBRARIES}) + add_executable(spidev_test spidev_test.c) add_executable(gpio2spi switchPinCtrl.c) diff --git a/test/TestQRegExp.cpp b/test/TestQRegExp.cpp new file mode 100644 index 00000000..efc74227 --- /dev/null +++ b/test/TestQRegExp.cpp @@ -0,0 +1,50 @@ + +// STL includes +#include + +// QT includes +#include +#include +#include + +int main() +{ + QString testString = "1-9, 11, 12,13,16-17"; + + QRegExp overallExp("([0-9]+(\\-[0-9]+)?)(,[ ]*([0-9]+(\\-[0-9]+)?))*"); + { + + std::cout << "[1] Match found: " << (overallExp.exactMatch("5")?"true":"false") << std::endl; + std::cout << "[1] Match found: " << (overallExp.exactMatch("4-")?"true":"false") << std::endl; + std::cout << "[1] Match found: " << (overallExp.exactMatch("-4")?"true":"false") << std::endl; + std::cout << "[1] Match found: " << (overallExp.exactMatch("3-9")?"true":"false") << std::endl; + std::cout << "[1] Match found: " << (overallExp.exactMatch("1-90")?"true":"false") << std::endl; + std::cout << "[1] Match found: " << (overallExp.exactMatch("1-90,100")?"true":"false") << std::endl; + std::cout << "[1] Match found: " << (overallExp.exactMatch("1-90, 100")?"true":"false") << std::endl; + std::cout << "[1] Match found: " << (overallExp.exactMatch("1-90, 100-200")?"true":"false") << std::endl; + std::cout << "[1] Match found: " << (overallExp.exactMatch("1-90, 100-200, 100")?"true":"false") << std::endl; + } + { + if (!overallExp.exactMatch(testString)) { + std::cout << "No correct match" << std::endl; + return -1; + } + QStringList splitString = testString.split(QChar(',')); + for (int i=0; i " << startInd << "-" << endInd << std::endl; + } + else + { + int index = splitString[i].toInt(); + std::cout << "==> " << index << std::endl; + } + } + } + + return 0; +}