1 #ifndef GETANDDOSTUFFCONTEXTTEST_H 2 #define GETANDDOSTUFFCONTEXTTEST_H 3 4 #include <QtTest/QTest> 5 #include "../scripts/getanddostuff/context.h" 6 #include "../scripts/getanddostuff/file.h" 7 #include "../scripts/getanddostuff/manipulation.h" 8 #include "../scripts/getanddostuff/other.h" 9 10 class GetAndDoStuffTest : public QObject { 11 12 Q_OBJECT 13 14 private slots: checkIfBinaryExists()15 void checkIfBinaryExists() { 16 GetAndDoStuffContext context; 17 QCOMPARE(context.checkIfBinaryExists("abcdefghijklmnopqrstuvwxyz1234567890.abc"), false); 18 QCOMPARE(context.checkIfBinaryExists("sh"), true); 19 QCOMPARE(context.checkIfBinaryExists(""), false); 20 } 21 removePathFromFilename()22 void removePathFromFilename() { 23 GetAndDoStuffFile file; 24 QCOMPARE(file.removePathFromFilename("/the/path/file.txt"), "file.txt"); 25 QCOMPARE(file.removePathFromFilename("/the/path/file.txt", false), "file.txt"); 26 QCOMPARE(file.removePathFromFilename("/the/path/file.txt", true), "file"); 27 QCOMPARE(file.removePathFromFilename(""), ""); 28 } 29 removeFilenameFromPath()30 void removeFilenameFromPath() { 31 GetAndDoStuffFile file; 32 QCOMPARE(file.removeFilenameFromPath("/the/path/file"), "/the/path"); 33 QCOMPARE(file.removeFilenameFromPath("file://the/path/file"), "/the/path"); 34 QCOMPARE(file.removeFilenameFromPath("file:///the/path/file"), "/the/path"); 35 QCOMPARE(file.removeFilenameFromPath("image://full//the/path/file"), "/the/path"); 36 QCOMPARE(file.removeFilenameFromPath(""), ""); 37 } 38 doesThisExist()39 void doesThisExist() { 40 GetAndDoStuffFile file; 41 QString path = QDir::currentPath(); 42 QCOMPARE(file.doesThisExist(path), true); 43 QCOMPARE(file.doesThisExist("file://" + path), true); 44 QCOMPARE(file.doesThisExist("file:/" + path), true); 45 QCOMPARE(file.doesThisExist("image://full/" + path), true); 46 QCOMPARE(file.doesThisExist("file:/" + path), true); 47 QCOMPARE(file.doesThisExist("abcdefghijklmnopqrstuvwxyz1234567890.abc"), false); 48 QCOMPARE(file.doesThisExist(""), false); 49 } 50 canBeScaled()51 void canBeScaled() { 52 GetAndDoStuffManipulation manip; 53 QCOMPARE(manip.canBeScaled("/the/path/file.jpg"), true); 54 QCOMPARE(manip.canBeScaled("/the/path/file.JPG"), true); 55 QCOMPARE(manip.canBeScaled("/the/path/file.JpG"), true); 56 QCOMPARE(manip.canBeScaled("/the/path/file.html"), false); 57 QCOMPARE(manip.canBeScaled(""), false); 58 } 59 convertRgbaToHex()60 void convertRgbaToHex() { 61 GetAndDoStuffOther other; 62 QCOMPARE(other.convertRgbaToHex(173, 32, 1, 88), "#58ad2001"); 63 QCOMPARE(other.convertRgbaToHex(-100, -1, 256, 400), "#ff0000ff"); 64 } 65 66 }; 67 68 #endif // GETANDDOSTUFFCONTEXTTEST_H 69