Warning, /plasma/discover/discover/autotests/DiscoverTest.qml is written in an unsupported language. File is not indexed.
0001 import QtQuick 2.1 0002 import QtTest 1.1 0003 import org.kde.discover.app 1.0 0004 0005 Item 0006 { 0007 id: testRoot 0008 0009 signal reset() 0010 property QtObject appRoot 0011 0012 function verify(condition, msg) { 0013 if (!condition) { 0014 console.trace(); 0015 var e = new Error(condition + (msg ? (": " + msg) : "")) 0016 e.object = testRoot; 0017 throw e; 0018 } 0019 } 0020 0021 function compare(valA, valB, msg) { 0022 if (valA !== valB) { 0023 console.trace(); 0024 var e = new Error(valA + " !== " + valB + (msg ? (": " + msg) : "")) 0025 e.object = testRoot; 0026 throw e; 0027 } 0028 } 0029 0030 function typeName(obj) { 0031 var name = obj.toString(); 0032 var idx = name.indexOf("_QMLTYPE_"); 0033 return name.substring(0, idx); 0034 } 0035 0036 function isType(obj, typename) { 0037 return obj && obj.toString().indexOf(typename+"_QMLTYPE_") === 0 0038 } 0039 0040 function chooseChildren(objects, validator) { 0041 for (var v in objects) { 0042 var obj = objects[v]; 0043 if (validator(obj)) 0044 return true; 0045 } 0046 return false; 0047 } 0048 0049 function chooseChild(obj, validator) { 0050 verify(obj, "can't find a null's child") 0051 if (validator(obj)) 0052 return true; 0053 var children = obj.data ? obj.data : obj.contentData 0054 for(var v in children) { 0055 var stop = chooseChild(children[v], validator) 0056 if (stop) 0057 return true 0058 } 0059 return false 0060 } 0061 0062 function findChild(obj, typename) { 0063 var ret = null; 0064 chooseChild(obj, function(o) { 0065 var found = isType(o, typename); 0066 if (found) { 0067 ret = o; 0068 } 0069 return found 0070 }) 0071 return ret; 0072 } 0073 0074 SignalSpy { 0075 id: spy 0076 } 0077 0078 function waitForSignal(object, name, timeout) { 0079 if (!timeout) timeout = 5000; 0080 0081 spy.clear(); 0082 spy.signalName = "" 0083 spy.target = object; 0084 spy.signalName = name; 0085 verify(spy); 0086 verify(spy.valid); 0087 verify(spy.count == 0); 0088 0089 try { 0090 spy.wait(timeout); 0091 } catch (e) { 0092 console.warn("wait for signal '"+name+"' failed") 0093 return false; 0094 } 0095 return spy.count>0; 0096 } 0097 0098 function waitForRendering() { 0099 return waitForSignal(appRoot, "frameSwapped") 0100 } 0101 0102 property string currentTest: "<null>" 0103 onCurrentTestChanged: console.log("changed to test", currentTest) 0104 0105 Connections { 0106 target: ResourcesModel 0107 property bool done: false 0108 function onIsFetchingChanged() { 0109 if (ResourcesModel.isFetching || done) 0110 return; 0111 0112 done = true; 0113 for(var v in testRoot) { 0114 if (v.indexOf("test_") === 0) { 0115 console.log("doing", v) 0116 testRoot.currentTest = v; 0117 testRoot.reset(); 0118 testRoot[v](); 0119 } 0120 } 0121 console.log("done") 0122 appRoot.close() 0123 } 0124 } 0125 }