|
| 1 | +script "CoreFilesSave" |
| 2 | +/* |
| 3 | +Copyright (C) 2016 LiveCode Ltd. |
| 4 | +
|
| 5 | +This file is part of LiveCode. |
| 6 | +
|
| 7 | +LiveCode is free software; you can redistribute it and/or modify it under |
| 8 | +the terms of the GNU General Public License v3 as published by the Free |
| 9 | +Software Foundation. |
| 10 | +
|
| 11 | +LiveCode is distributed in the hope that it will be useful, but WITHOUT ANY |
| 12 | +WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 13 | +FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
| 14 | +for more details. |
| 15 | +
|
| 16 | +You should have received a copy of the GNU General Public License |
| 17 | +along with LiveCode. If not see <http://www.gnu.org/licenses/>. */ |
| 18 | + |
| 19 | +constant kTestDirectory = "__CoreFilesSave" |
| 20 | +constant kTestFile = "__CoreFilesSave/Save.livecode" |
| 21 | +constant kVersions = "8.0:7000,7.0:7000,5.5:5500,2.7:2700" |
| 22 | +constant kVersionsWidget = "8.0:8000,7.0:7000,5.5:5500,2.7:2700" |
| 23 | + |
| 24 | +local sTestStack, sTestStackWidget |
| 25 | + |
| 26 | +command TestSetup |
| 27 | + create folder kTestDirectory |
| 28 | + |
| 29 | + create invisible stack "non-widget" |
| 30 | + put it into sTestStack |
| 31 | + |
| 32 | + create invisible stack "widget" |
| 33 | + put it into sTestStackWidget |
| 34 | + set the defaultstack to sTestStackWidget |
| 35 | + TestLoadExtension "com.livecode.widget.clock" |
| 36 | + create widget as "com.livecode.widget.clock" |
| 37 | +end TestSetup |
| 38 | + |
| 39 | +command TestTearDown |
| 40 | + local tFile, tFolder |
| 41 | + put the defaultfolder into tFolder |
| 42 | + set the defaultfolder to kTestDirectory |
| 43 | + repeat for each line tFile in the files |
| 44 | + delete file tFile |
| 45 | + end repeat |
| 46 | + set the defaultfolder to tFolder |
| 47 | + delete folder kTestDirectory |
| 48 | +end TestTearDown |
| 49 | + |
| 50 | +private command __TestStackFileHasFormat pVersion |
| 51 | + local tActual, tExpected, tVersion |
| 52 | + |
| 53 | + set the itemdelimiter to ":" |
| 54 | + put item 1 of pVersion into tVersion |
| 55 | + put "REVO" & item 2 of pVersion into tExpected |
| 56 | + |
| 57 | + open file kTestFile for binary read |
| 58 | + read from file kTestFile for 8 bytes |
| 59 | + put it into tActual |
| 60 | + close file kTestFile |
| 61 | + |
| 62 | + TestAssert merge("stack file has version [[tVersion]]"), tActual is tExpected |
| 63 | + TestDiagnostic merge("version was '[[tActual]]'") |
| 64 | +end __TestStackFileHasFormat |
| 65 | + |
| 66 | +private command __TestSaveAsFormat pStack, pVersion |
| 67 | + local tVersion, tName |
| 68 | + set the itemdelimiter to ":" |
| 69 | + put item 1 of pVersion into tVersion |
| 70 | + put the name of pStack into tName |
| 71 | + |
| 72 | + save pStack as kTestFile with format tVersion |
| 73 | + TestAssert merge("save [[tName]] stack file with version [[tVersion]]"), the result is empty |
| 74 | + |
| 75 | + __TestStackFileHasFormat pVersion |
| 76 | +end __TestSaveAsFormat |
| 77 | + |
| 78 | +private command __TestSaveAsNewestFormat pStack, pVersion |
| 79 | + local tName |
| 80 | + put the name of pStack into tName |
| 81 | + save pStack as kTestFile with newest format |
| 82 | + TestAssert "save [[tName]] stack file with newest version", the result is empty |
| 83 | + |
| 84 | + __TestStackFileHasFormat pVersion |
| 85 | +end __TestSaveAsNewestFormat |
| 86 | + |
| 87 | +private command __TestSaveAsGlobalFormat pStack, pVersion |
| 88 | + local tVersion, tName |
| 89 | + set the itemdelimiter to ":" |
| 90 | + put item 1 of pVersion into tVersion |
| 91 | + put the name of pStack into tName |
| 92 | + |
| 93 | + set the stackfileversion to tVersion |
| 94 | + save pStack as kTestFile |
| 95 | + TestAssert merge("save [[tName]] stack file with version [[tVersion]]"), the result is empty |
| 96 | + |
| 97 | + __TestStackFileHasFormat pVersion |
| 98 | +end __TestSaveAsGlobalFormat |
| 99 | + |
| 100 | +private command __TestSaveAsDefaultFormat pStack, pVersion |
| 101 | + local tName |
| 102 | + put the name of pStack into tName |
| 103 | + save pStack as kTestFile |
| 104 | + TestAssert merge("save [[tName]] stack file with default version"), the result is empty |
| 105 | + |
| 106 | + __TestStackFileHasFormat pVersion |
| 107 | +end __TestSaveAsDefaultFormat |
| 108 | + |
| 109 | +on TestSaveAsFormat |
| 110 | + local tVersion |
| 111 | + |
| 112 | + set the itemdelimiter to "," |
| 113 | + repeat for each item tVersion in kVersions |
| 114 | + __TestSaveAsFormat sTestStack, tVersion |
| 115 | + end repeat |
| 116 | + repeat for each item tVersion in kVersionsWidget |
| 117 | + __TestSaveAsFormat sTestStackWidget, tVersion |
| 118 | + end repeat |
| 119 | +end TestSaveAsFormat |
| 120 | + |
| 121 | +on TestSaveAsNewestFormat |
| 122 | + local tVersion |
| 123 | + |
| 124 | + set the itemdelimiter to "," |
| 125 | + __TestSaveAsNewestFormat sTestStack, item 1 of kVersions |
| 126 | + __TestSaveAsNewestFormat sTestStackWidget, item 1 of kVersionsWidget |
| 127 | +end TestSaveAsNewestFormat |
| 128 | + |
| 129 | +on TestSaveAsGlobalFormat |
| 130 | + local tVersion |
| 131 | + |
| 132 | + set the itemdelimiter to "," |
| 133 | + repeat for each item tVersion in kVersions |
| 134 | + __TestSaveAsGlobalFormat sTestStack, tVersion |
| 135 | + end repeat |
| 136 | + repeat for each item tVersion in kVersionsWidget |
| 137 | + __TestSaveAsGlobalFormat sTestStackWidget, tVersion |
| 138 | + end repeat |
| 139 | +end TestSaveAsGlobalFormat |
| 140 | + |
| 141 | +on TestSaveAsDefaultFormat |
| 142 | + local tVersion |
| 143 | + set the itemdelimiter to "," |
| 144 | + __TestSaveAsDefaultFormat sTestStack, item 1 of kVersions |
| 145 | + __TestSaveAsDefaultFormat sTestStackWidget, item 1 of kVersionsWidget |
| 146 | +end TestSaveAsDefaultFormat |
0 commit comments