StrFunc.nsi 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562
  1. Name "NSIS StrFunc Example"
  2. OutFile "StrFunc.exe"
  3. ShowInstDetails show
  4. ShowUninstDetails show
  5. XPStyle on
  6. RequestExecutionLevel user
  7. !include "StrFunc.nsh"
  8. # Declare used functions
  9. ${StrCase}
  10. ${StrClb}
  11. ${StrIOToNSIS}
  12. ${StrLoc}
  13. ${StrNSISToIO}
  14. ${StrRep}
  15. ${StrStr}
  16. ${StrStrAdv}
  17. ${StrTok}
  18. ${StrTrimNewLines}
  19. ${StrSort}
  20. ${UnStrCase}
  21. ${UnStrClb}
  22. ${UnStrIOToNSIS}
  23. ${UnStrLoc}
  24. ${UnStrNSISToIO}
  25. ${UnStrRep}
  26. ${UnStrStr}
  27. ${UnStrStrAdv}
  28. ${UnStrTok}
  29. ${UnStrTrimNewLines}
  30. ${UnStrSort}
  31. Var SFPass
  32. Var SFTotl
  33. !macro EndStrFuncTestEx lbl name
  34. IfErrors ${lbl}
  35. DetailPrint "PASSED ${name} test"
  36. IntOp $SFPass $SFPass + 1
  37. IntOp $SFTotl $SFTotl + 1
  38. Goto +3
  39. ${lbl}:
  40. DetailPrint "FAILED ${name} test"
  41. IntOp $SFTotl $SFTotl + 1
  42. !macroend
  43. !macro EndStrFuncTest name
  44. !insertmacro EndStrFuncTestEx "${name}error" "${name}"
  45. !macroend
  46. CompletedText "Passed $SFPass of $SFTotl tests"
  47. !macro CompletedAllTests
  48. StrCmp $SFPass $SFTotl +2
  49. SetErrorLevel 42
  50. !macroend
  51. !macro StackVerificationStart
  52. StrCpy $0 S0
  53. StrCpy $1 S1
  54. StrCpy $2 S2
  55. StrCpy $3 S3
  56. StrCpy $4 S4
  57. StrCpy $5 S5
  58. StrCpy $6 S6
  59. StrCpy $7 S7
  60. StrCpy $8 S8
  61. StrCpy $9 S9
  62. StrCpy $R0 SR0
  63. StrCpy $R1 SR1
  64. StrCpy $R2 SR2
  65. StrCpy $R3 SR3
  66. StrCpy $R4 SR4
  67. StrCpy $R5 SR5
  68. StrCpy $R6 SR6
  69. StrCpy $R7 SR7
  70. StrCpy $R8 SR8
  71. StrCpy $R9 SR9
  72. !macroend
  73. !macro StackVerificationEnd
  74. ClearErrors
  75. ${If} $1 != "S1"
  76. ${OrIf} $2 != "S2"
  77. ${OrIf} $3 != "S3"
  78. ${OrIf} $4 != "S4"
  79. ${OrIf} $5 != "S5"
  80. ${OrIf} $6 != "S6"
  81. ${OrIf} $7 != "S7"
  82. ${OrIf} $8 != "S8"
  83. ${OrIf} $9 != "S9"
  84. ${OrIf} $R0 != "SR0"
  85. ${OrIf} $R1 != "SR1"
  86. ${OrIf} $R2 != "SR2"
  87. ${OrIf} $R3 != "SR3"
  88. ${OrIf} $R4 != "SR4"
  89. ${OrIf} $R5 != "SR5"
  90. ${OrIf} $R6 != "SR6"
  91. ${OrIf} $R7 != "SR7"
  92. ${OrIf} $R8 != "SR8"
  93. ${OrIf} $R9 != "SR9"
  94. SetErrors
  95. ${EndIf}
  96. !macroend
  97. Section
  98. # Test case conversion
  99. !insertmacro StackVerificationStart
  100. ${StrCase} $0 "This is just an example. A very simple one." ""
  101. StrCmp $0 "This is just an example. A very simple one." 0 strcaseerror
  102. ${StrCase} $0 "THIS IS JUST AN EXAMPLE. A VERY SIMPLE ONE." "S"
  103. StrCmp $0 "This is just an example. A very simple one." 0 strcaseerror
  104. ${StrCase} $0 "This is just an example. A very simple one." "L"
  105. StrCmp $0 "this is just an example. a very simple one." 0 strcaseerror
  106. ${StrCase} $0 "This is just an example. A very simple one." "U"
  107. StrCmp $0 "THIS IS JUST AN EXAMPLE. A VERY SIMPLE ONE." 0 strcaseerror
  108. ${StrCase} $0 "This is just an example. A very simple one." "T"
  109. StrCmp $0 "This Is Just An Example. A Very Simple One." 0 strcaseerror
  110. ${StrCase} $0 "This is just an example. A very simple one." "<>"
  111. StrCmp $0 "tHIS IS JUST AN EXAMPLE. a VERY SIMPLE ONE." 0 strcaseerror
  112. ${StrCase} $0 "123456789!@#%^&*()-_=+[]{};:,./<>?" "S"
  113. StrCmp $0 "123456789!@#%^&*()-_=+[]{};:,./<>?" 0 strcaseerror
  114. ${StrCase} $0 "123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ!@#%^&*()abcdefghijklmnopqrstuvwxyz-_=+[]{};:,./<>?" "<>"
  115. StrCmp $0 "123456789abcdefghijklmnopqrstuvwxyz!@#%^&*()ABCDEFGHIJKLMNOPQRSTUVWXYZ-_=+[]{};:,./<>?" 0 strcaseerror
  116. ${StrCase} $0 "what about taking a shower tomorrow? it's late to do so now! try to sleep now. Good Night!" "S"
  117. StrCmp $0 "What about taking a shower tomorrow? It's late to do so now! Try to sleep now. Good night!" 0 strcaseerror
  118. !insertmacro StackVerificationEnd
  119. !insertmacro EndStrFuncTest StrCase
  120. # Test clipboard function
  121. !insertmacro StackVerificationStart
  122. !verbose push 4
  123. ${StrClb} $0 "StrFunc clipboard test" ">"
  124. !verbose pop
  125. StrCmp $0 "" 0 strclberror
  126. ${StrClb} $0 "StrFunc clipboard test #2" "<>"
  127. StrCmp $0 "StrFunc clipboard test" 0 strclberror
  128. ${StrClb} $0 "" "<"
  129. StrCmp $0 "StrFunc clipboard test #2" 0 strclberror
  130. ${StrClb} $0 "" ""
  131. StrCmp $0 "" 0 strclberror
  132. !insertmacro StackVerificationEnd
  133. !insertmacro EndStrFuncTest StrClb
  134. # Test IO functions
  135. !insertmacro StackVerificationStart
  136. !macro testio str
  137. ${StrNSISToIO} $0 "${str}"
  138. ${StrIOToNSIS} $0 $0
  139. StrCmp $0 "${str}" 0 ioerror
  140. !macroend
  141. !insertmacro testio "$\rtest$\n"
  142. !insertmacro testio "test$\n"
  143. !insertmacro testio "$\rtest"
  144. !insertmacro testio "test"
  145. !insertmacro testio "$\r\$\t$\n"
  146. !insertmacro testio "$\r \ $\t $\n $$"
  147. !insertmacro testio ""
  148. !insertmacro testio " "
  149. !insertmacro StackVerificationEnd
  150. !insertmacro EndStrFuncTestEx ioerror "StrNSISToIO/StrIOToNSIS"
  151. # Test string search functions
  152. !insertmacro StackVerificationStart
  153. ${StrLoc} $0 "This is just an example" "just" "<"
  154. StrCmp $0 "11" 0 strlocerror
  155. ${StrLoc} $0 a abc <
  156. StrCmp $0 "" 0 strlocerror
  157. ${StrLoc} $0 a abc >
  158. StrCmp $0 "" 0 strlocerror
  159. ${StrLoc} $0 abc a >
  160. StrCmp $0 "0" 0 strlocerror
  161. ${StrLoc} $0 abc b >
  162. StrCmp $0 "1" 0 strlocerror
  163. ${StrLoc} $0 abc c >
  164. StrCmp $0 "2" 0 strlocerror
  165. ${StrLoc} $0 abc a <
  166. StrCmp $0 "2" 0 strlocerror
  167. ${StrLoc} $0 abc b <
  168. StrCmp $0 "1" 0 strlocerror
  169. ${StrLoc} $0 abc c <
  170. StrCmp $0 "0" 0 strlocerror
  171. ${StrLoc} $0 abc d <
  172. StrCmp $0 "" 0 strlocerror
  173. !insertmacro StackVerificationEnd
  174. !insertmacro EndStrFuncTest StrLoc
  175. # Test string replacement
  176. !insertmacro StackVerificationStart
  177. ${StrRep} $0 "This is just an example" "an" "one"
  178. StrCmp $0 "This is just one example" 0 strreperror
  179. ${StrRep} $0 "test... test... 1 2 3..." "test" "testing"
  180. StrCmp $0 "testing... testing... 1 2 3..." 0 strreperror
  181. ${StrRep} $0 "" "test" "testing"
  182. StrCmp $0 "" 0 strreperror
  183. ${StrRep} $0 "test" "test" "testing"
  184. StrCmp $0 "testing" 0 strreperror
  185. ${StrRep} $0 "test" "test" ""
  186. StrCmp $0 "" 0 strreperror
  187. ${StrRep} $0 "test" "" "abc"
  188. StrCmp $0 "test" 0 strreperror
  189. ${StrRep} $0 "test" "" ""
  190. StrCmp $0 "test" 0 strreperror
  191. !insertmacro StackVerificationEnd
  192. !insertmacro EndStrFuncTest StrRep
  193. # Test sorting
  194. !insertmacro StackVerificationStart
  195. ${StrSort} $0 "This is just an example" "" " just" "ple" "0" "0" "0"
  196. StrCmp $0 "This is an exam" 0 strsorterror
  197. ${StrSort} $0 "This is just an example" " " "j" " " "0" "" "0"
  198. StrCmp $0 "just" 0 strsorterror
  199. ${StrSort} $0 "This is just an example" "" "j" "" "0" "1" "0"
  200. StrCmp $0 "This is just an example" 0 strsorterror
  201. ${StrSort} $0 "This is just an example" " " "us" "" "0" "1" "0"
  202. StrCmp $0 "just an example" 0 strsorterror
  203. ${StrSort} $0 "This is just an example" "" "u" " " "0" "1" "0"
  204. StrCmp $0 "This is just" 0 strsorterror
  205. ${StrSort} $0 "This is just an example" " " "just" " " "0" "1" "0"
  206. StrCmp $0 "just" 0 strsorterror
  207. ${StrSort} $0 "This is just an example" " " "t" " " "0" "1" "0"
  208. StrCmp $0 "This" 0 strsorterror
  209. ${StrSort} $0 "This is just an example" " " "le" " " "0" "1" "0"
  210. StrCmp $0 "example" 0 strsorterror
  211. ${StrSort} $0 "This is just an example" " " "le" " " "1" "0" "0"
  212. StrCmp $0 " examp" 0 strsorterror
  213. ${StrSort} $0 "an error has occurred" " " "e" " " "0" "1" "0"
  214. StrCmp $0 "error" 0 strsorterror
  215. ${StrSort} $0 "" " " "something" " " "0" "1" "0"
  216. StrCmp $0 "" 0 strsorterror
  217. ${StrSort} $0 "This is just an example" " " "j" " " "" "" ""
  218. StrCmp $0 " just " 0 strsorterror
  219. ${StrSort} $0 "This is just an example" " " "j" " " "1" "0" "1"
  220. StrCmp $0 " ust " 0 strsorterror
  221. ${StrSort} $0 "This is just an example" "" "j" "" "0" "0" "1"
  222. StrCmp $0 "This is ust an example" 0 strsorterror
  223. ${StrSort} $0 "This is just an example" " " "us" "" "1" "0" "0"
  224. StrCmp $0 " jt an example" 0 strsorterror
  225. ${StrSort} $0 "This is just an example" "" "u" " " "0" "0" "1"
  226. StrCmp $0 "This is jst " 0 strsorterror
  227. ${StrSort} $0 "This is just an example" " " "just" " " "1" "0" "1"
  228. StrCmp $0 " " 0 strsorterror
  229. ${StrSort} $0 "an error has occurred" " " "e" "h" "1" "0" "0"
  230. StrCmp $0 " rror " 0 strsorterror
  231. ${StrSort} $0 "" " " "something" " " "1" "0" "1"
  232. StrCmp $0 "" 0 strsorterror
  233. !insertmacro StackVerificationEnd
  234. !insertmacro EndStrFuncTest StrSort
  235. !insertmacro StackVerificationStart
  236. ${StrStr} $0 "abcefghijklmnopqrstuvwxyz" "g"
  237. StrCmp $0 "ghijklmnopqrstuvwxyz" 0 strstrerror
  238. ${StrStr} $0 "abcefghijklmnopqrstuvwxyz" "ga"
  239. StrCmp $0 "" 0 strstrerror
  240. ${StrStr} $0 "abcefghijklmnopqrstuvwxyz" ""
  241. StrCmp $0 "abcefghijklmnopqrstuvwxyz" 0 strstrerror
  242. ${StrStr} $0 "a" "abcefghijklmnopqrstuvwxyz"
  243. StrCmp $0 "" 0 strstrerror
  244. !insertmacro StackVerificationEnd
  245. !insertmacro EndStrFuncTest StrStr
  246. !insertmacro StackVerificationStart
  247. ${StrStrAdv} $0 "abcabcabc" "a" ">" ">" "1" "0" "0"
  248. StrCmp $0 "abcabcabc" 0 strstradverror
  249. ${StrStrAdv} $0 "abcabcabc" "a" ">" ">" "1" "1" "0"
  250. StrCmp $0 "abcabc" 0 strstradverror
  251. ${StrStrAdv} $0 "abcabcabc" "a" ">" ">" "1" "2" "0"
  252. StrCmp $0 "abc" 0 strstradverror
  253. ${StrStrAdv} $0 "abcabcabc" "a" ">" ">" "1" "3" "0"
  254. StrCmp $0 "" 0 strstradverror
  255. ${StrStrAdv} $0 "abcabcabc" "abc" ">" "<" "1" "1" "0"
  256. StrCmp $0 "abcabc" 0 strstradverror
  257. ${StrStrAdv} $0 "abcabcabc" "abc" ">" "<" "0" "1" "0"
  258. StrCmp $0 "abc" 0 strstradverror
  259. ${StrStrAdv} $0 "abcabcabc" "abc" "<" "<" "1" "0" "0"
  260. StrCmp $0 "abcabcabc" 0 strstradverror
  261. ${StrStrAdv} $0 "abcabcabc" "abc" "<" "<" "0" "0" "0"
  262. StrCmp $0 "abcabc" 0 strstradverror
  263. ${StrStrAdv} $0 "abcabcabc" "abc" "<" ">" "0" "0" "0"
  264. StrCmp $0 "" 0 strstradverror
  265. ${StrStrAdv} $0 "abcabcabc" "abc" "<" ">" "0" "1" "0"
  266. StrCmp $0 "abc" 0 strstradverror
  267. ${StrStrAdv} $0 "ABCabcabc" "a" ">" ">" "1" "0" "1"
  268. StrCmp $0 "abcabc" 0 strstradverror
  269. ${StrStrAdv} $0 "ABCabcabc" "a" ">" ">" "1" "1" "1"
  270. StrCmp $0 "abc" 0 strstradverror
  271. ${StrStrAdv} $0 "ABCabcabc" "a" ">" ">" "1" "2" "1"
  272. StrCmp $0 "" 0 strstradverror
  273. ${StrStrAdv} $0 "ABCabcabc" "a" ">" ">" "1" "3" "1"
  274. StrCmp $0 "" 0 strstradverror
  275. ${StrStrAdv} $0 "ABCabcabc" "abc" ">" "<" "1" "1" "1"
  276. StrCmp $0 "ABCabcabc" 0 strstradverror
  277. ${StrStrAdv} $0 "ABCabcabc" "abc" ">" "<" "0" "1" "1"
  278. StrCmp $0 "ABCabc" 0 strstradverror
  279. ${StrStrAdv} $0 "ABCabcabc" "abc" "<" "<" "1" "0" "1"
  280. StrCmp $0 "ABCabcabc" 0 strstradverror
  281. ${StrStrAdv} $0 "ABCabcabc" "abc" "<" "<" "0" "0" "1"
  282. StrCmp $0 "ABCabc" 0 strstradverror
  283. ${StrStrAdv} $0 "ABCabcabc" "abc" "<" ">" "0" "0" "1"
  284. StrCmp $0 "" 0 strstradverror
  285. ${StrStrAdv} $0 "ABCabcabc" "abc" "<" ">" "0" "1" "1"
  286. StrCmp $0 "abc" 0 strstradverror
  287. !insertmacro StackVerificationEnd
  288. !insertmacro EndStrFuncTest StrStrAdv
  289. # Test tokenizer
  290. !insertmacro StackVerificationStart
  291. ${StrTok} $0 "This is, or is not, just an example" " ," "4" "1"
  292. StrCmp $0 "not" 0 strtokerror
  293. ${StrTok} $0 "This is, or is not, just an example" " ," "4" "0"
  294. StrCmp $0 "is" 0 strtokerror
  295. ${StrTok} $0 "This is, or is not, just an example" " ," "152" "0"
  296. StrCmp $0 "" 0 strtokerror
  297. ${StrTok} $0 "This is, or is not, just an example" " ," "" "0"
  298. StrCmp $0 "example" 0 strtokerror
  299. ${StrTok} $0 "This is, or is not, just an example" " ," "L" "0"
  300. StrCmp $0 "example" 0 strtokerror
  301. ${StrTok} $0 "This is, or is not, just an example" " ," "0" "0"
  302. StrCmp $0 "This" 0 strtokerror
  303. !insertmacro StackVerificationEnd
  304. !insertmacro EndStrFuncTest StrTok
  305. # Test trim new lines
  306. !insertmacro StackVerificationStart
  307. ${StrTrimNewLines} $0 "$\r$\ntest$\r$\ntest$\r$\n"
  308. StrCmp $0 "$\r$\ntest$\r$\ntest" 0 strtrimnewlineserror
  309. !insertmacro StackVerificationEnd
  310. !insertmacro EndStrFuncTest StrTrimNewlines
  311. InitPluginsDir
  312. WriteUninstaller $PluginsDir\UnStrFunc.exe
  313. ExecWait '"$PluginsDir\UnStrFunc.exe" _?=$PluginsDir'
  314. !insertmacro CompletedAllTests
  315. SectionEnd
  316. Section Uninstall
  317. # Test case conversion
  318. !insertmacro StackVerificationStart
  319. ${UnStrCase} $0 "This is just an example. A very simple one." ""
  320. StrCmp $0 "This is just an example. A very simple one." 0 strcaseerror
  321. ${UnStrCase} $0 "THIS IS JUST AN EXAMPLE. A VERY SIMPLE ONE." "S"
  322. StrCmp $0 "This is just an example. A very simple one." 0 strcaseerror
  323. ${UnStrCase} $0 "This is just an example. A very simple one." "L"
  324. StrCmp $0 "this is just an example. a very simple one." 0 strcaseerror
  325. ${UnStrCase} $0 "This is just an example. A very simple one." "U"
  326. StrCmp $0 "THIS IS JUST AN EXAMPLE. A VERY SIMPLE ONE." 0 strcaseerror
  327. ${UnStrCase} $0 "This is just an example. A very simple one." "T"
  328. StrCmp $0 "This Is Just An Example. A Very Simple One." 0 strcaseerror
  329. ${UnStrCase} $0 "This is just an example. A very simple one." "<>"
  330. StrCmp $0 "tHIS IS JUST AN EXAMPLE. a VERY SIMPLE ONE." 0 strcaseerror
  331. ${UnStrCase} $0 "123456789!@#%^&*()-_=+[]{};:,./<>?" "S"
  332. StrCmp $0 "123456789!@#%^&*()-_=+[]{};:,./<>?" 0 strcaseerror
  333. ${UnStrCase} $0 "123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ!@#%^&*()abcdefghijklmnopqrstuvwxyz-_=+[]{};:,./<>?" "<>"
  334. StrCmp $0 "123456789abcdefghijklmnopqrstuvwxyz!@#%^&*()ABCDEFGHIJKLMNOPQRSTUVWXYZ-_=+[]{};:,./<>?" 0 strcaseerror
  335. ${UnStrCase} $0 "what about taking a shower tomorrow? it's late to do so now! try to sleep now. Good Night!" "S"
  336. StrCmp $0 "What about taking a shower tomorrow? It's late to do so now! Try to sleep now. Good night!" 0 strcaseerror
  337. !insertmacro StackVerificationEnd
  338. !insertmacro EndStrFuncTest StrCase
  339. # Test clipboard function
  340. !insertmacro StackVerificationStart
  341. ${UnStrClb} $0 "StrFunc clipboard test" ">"
  342. StrCmp $0 "" 0 strclberror
  343. ${UnStrClb} $0 "StrFunc clipboard test #2" "<>"
  344. StrCmp $0 "StrFunc clipboard test" 0 strclberror
  345. ${UnStrClb} $0 "" "<"
  346. StrCmp $0 "StrFunc clipboard test #2" 0 strclberror
  347. ${UnStrClb} $0 "" ""
  348. StrCmp $0 "" 0 strclberror
  349. !insertmacro StackVerificationEnd
  350. !insertmacro EndStrFuncTest StrClb
  351. # Test IO functions
  352. !insertmacro StackVerificationStart
  353. !macro untestio str
  354. ${UnStrNSISToIO} $0 "${str}"
  355. ${UnStrIOToNSIS} $0 $0
  356. StrCmp $0 "${str}" 0 ioerror
  357. !macroend
  358. !insertmacro untestio "$\rtest$\n"
  359. !insertmacro untestio "test$\n"
  360. !insertmacro untestio "$\rtest"
  361. !insertmacro untestio "test"
  362. !insertmacro untestio "$\r\$\t$\n"
  363. !insertmacro untestio "$\r \ $\t $\n $$"
  364. !insertmacro untestio ""
  365. !insertmacro untestio " "
  366. !insertmacro StackVerificationEnd
  367. !insertmacro EndStrFuncTestEx ioerror "StrNSISToIO/StrIOToNSIS"
  368. # Test string search functions
  369. !insertmacro StackVerificationStart
  370. ${UnStrLoc} $0 "This is just an example" "just" "<"
  371. StrCmp $0 "11" 0 strlocerror
  372. ${UnStrLoc} $0 a abc <
  373. StrCmp $0 "" 0 strlocerror
  374. ${UnStrLoc} $0 a abc >
  375. StrCmp $0 "" 0 strlocerror
  376. ${UnStrLoc} $0 abc a >
  377. StrCmp $0 "0" 0 strlocerror
  378. ${UnStrLoc} $0 abc b >
  379. StrCmp $0 "1" 0 strlocerror
  380. ${UnStrLoc} $0 abc c >
  381. StrCmp $0 "2" 0 strlocerror
  382. ${UnStrLoc} $0 abc a <
  383. StrCmp $0 "2" 0 strlocerror
  384. ${UnStrLoc} $0 abc b <
  385. StrCmp $0 "1" 0 strlocerror
  386. ${UnStrLoc} $0 abc c <
  387. StrCmp $0 "0" 0 strlocerror
  388. ${UnStrLoc} $0 abc d <
  389. StrCmp $0 "" 0 strlocerror
  390. !insertmacro StackVerificationEnd
  391. !insertmacro EndStrFuncTest StrLoc
  392. # Test string replacement
  393. !insertmacro StackVerificationStart
  394. ${UnStrRep} $0 "This is just an example" "an" "one"
  395. StrCmp $0 "This is just one example" 0 strreperror
  396. ${UnStrRep} $0 "test... test... 1 2 3..." "test" "testing"
  397. StrCmp $0 "testing... testing... 1 2 3..." 0 strreperror
  398. ${UnStrRep} $0 "" "test" "testing"
  399. StrCmp $0 "" 0 strreperror
  400. ${UnStrRep} $0 "test" "test" "testing"
  401. StrCmp $0 "testing" 0 strreperror
  402. ${UnStrRep} $0 "test" "test" ""
  403. StrCmp $0 "" 0 strreperror
  404. ${UnStrRep} $0 "test" "" "abc"
  405. StrCmp $0 "test" 0 strreperror
  406. ${UnStrRep} $0 "test" "" ""
  407. StrCmp $0 "test" 0 strreperror
  408. !insertmacro StackVerificationEnd
  409. !insertmacro EndStrFuncTest StrRep
  410. # Test sorting
  411. !insertmacro StackVerificationStart
  412. ${UnStrSort} $0 "This is just an example" "" " just" "ple" "0" "0" "0"
  413. StrCmp $0 "This is an exam" 0 strsorterror
  414. ${UnStrSort} $0 "This is just an example" " " "j" " " "0" "" "0"
  415. StrCmp $0 "just" 0 strsorterror
  416. ${UnStrSort} $0 "This is just an example" "" "j" "" "0" "1" "0"
  417. StrCmp $0 "This is just an example" 0 strsorterror
  418. ${UnStrSort} $0 "This is just an example" " " "us" "" "0" "1" "0"
  419. StrCmp $0 "just an example" 0 strsorterror
  420. ${UnStrSort} $0 "This is just an example" "" "u" " " "0" "1" "0"
  421. StrCmp $0 "This is just" 0 strsorterror
  422. ${UnStrSort} $0 "This is just an example" " " "just" " " "0" "1" "0"
  423. StrCmp $0 "just" 0 strsorterror
  424. ${UnStrSort} $0 "This is just an example" " " "t" " " "0" "1" "0"
  425. StrCmp $0 "This" 0 strsorterror
  426. ${UnStrSort} $0 "This is just an example" " " "le" " " "0" "1" "0"
  427. StrCmp $0 "example" 0 strsorterror
  428. ${UnStrSort} $0 "This is just an example" " " "le" " " "1" "0" "0"
  429. StrCmp $0 " examp" 0 strsorterror
  430. ${UnStrSort} $0 "an error has occurred" " " "e" " " "0" "1" "0"
  431. StrCmp $0 "error" 0 strsorterror
  432. ${UnStrSort} $0 "" " " "something" " " "0" "1" "0"
  433. StrCmp $0 "" 0 strsorterror
  434. ${UnStrSort} $0 "This is just an example" " " "j" " " "" "" ""
  435. StrCmp $0 " just " 0 strsorterror
  436. ${UnStrSort} $0 "This is just an example" " " "j" " " "1" "0" "1"
  437. StrCmp $0 " ust " 0 strsorterror
  438. ${UnStrSort} $0 "This is just an example" "" "j" "" "0" "0" "1"
  439. StrCmp $0 "This is ust an example" 0 strsorterror
  440. ${UnStrSort} $0 "This is just an example" " " "us" "" "1" "0" "0"
  441. StrCmp $0 " jt an example" 0 strsorterror
  442. ${UnStrSort} $0 "This is just an example" "" "u" " " "0" "0" "1"
  443. StrCmp $0 "This is jst " 0 strsorterror
  444. ${UnStrSort} $0 "This is just an example" " " "just" " " "1" "0" "1"
  445. StrCmp $0 " " 0 strsorterror
  446. ${UnStrSort} $0 "an error has occurred" " " "e" "h" "1" "0" "0"
  447. StrCmp $0 " rror " 0 strsorterror
  448. ${UnStrSort} $0 "" " " "something" " " "1" "0" "1"
  449. StrCmp $0 "" 0 strsorterror
  450. !insertmacro StackVerificationEnd
  451. !insertmacro EndStrFuncTest StrSort
  452. !insertmacro StackVerificationStart
  453. ${UnStrStr} $0 "abcefghijklmnopqrstuvwxyz" "g"
  454. StrCmp $0 "ghijklmnopqrstuvwxyz" 0 strstrerror
  455. ${UnStrStr} $0 "abcefghijklmnopqrstuvwxyz" "ga"
  456. StrCmp $0 "" 0 strstrerror
  457. ${UnStrStr} $0 "abcefghijklmnopqrstuvwxyz" ""
  458. StrCmp $0 "abcefghijklmnopqrstuvwxyz" 0 strstrerror
  459. ${UnStrStr} $0 "a" "abcefghijklmnopqrstuvwxyz"
  460. StrCmp $0 "" 0 strstrerror
  461. !insertmacro StackVerificationEnd
  462. !insertmacro EndStrFuncTest StrStr
  463. !insertmacro StackVerificationStart
  464. ${UnStrStrAdv} $0 "abcabcabc" "a" ">" ">" "1" "0" "0"
  465. StrCmp $0 "abcabcabc" 0 strstradverror
  466. ${UnStrStrAdv} $0 "abcabcabc" "a" ">" ">" "1" "1" "0"
  467. StrCmp $0 "abcabc" 0 strstradverror
  468. ${UnStrStrAdv} $0 "abcabcabc" "a" ">" ">" "1" "2" "0"
  469. StrCmp $0 "abc" 0 strstradverror
  470. ${UnStrStrAdv} $0 "abcabcabc" "a" ">" ">" "1" "3" "0"
  471. StrCmp $0 "" 0 strstradverror
  472. ${UnStrStrAdv} $0 "abcabcabc" "abc" ">" "<" "1" "1" "0"
  473. StrCmp $0 "abcabc" 0 strstradverror
  474. ${UnStrStrAdv} $0 "abcabcabc" "abc" ">" "<" "0" "1" "0"
  475. StrCmp $0 "abc" 0 strstradverror
  476. ${UnStrStrAdv} $0 "abcabcabc" "abc" "<" "<" "1" "0" "0"
  477. StrCmp $0 "abcabcabc" 0 strstradverror
  478. ${UnStrStrAdv} $0 "abcabcabc" "abc" "<" "<" "0" "0" "0"
  479. StrCmp $0 "abcabc" 0 strstradverror
  480. ${UnStrStrAdv} $0 "abcabcabc" "abc" "<" ">" "0" "0" "0"
  481. StrCmp $0 "" 0 strstradverror
  482. ${UnStrStrAdv} $0 "abcabcabc" "abc" "<" ">" "0" "1" "0"
  483. StrCmp $0 "abc" 0 strstradverror
  484. ${UnStrStrAdv} $0 "ABCabcabc" "a" ">" ">" "1" "0" "1"
  485. StrCmp $0 "abcabc" 0 strstradverror
  486. ${UnStrStrAdv} $0 "ABCabcabc" "a" ">" ">" "1" "1" "1"
  487. StrCmp $0 "abc" 0 strstradverror
  488. ${UnStrStrAdv} $0 "ABCabcabc" "a" ">" ">" "1" "2" "1"
  489. StrCmp $0 "" 0 strstradverror
  490. ${UnStrStrAdv} $0 "ABCabcabc" "a" ">" ">" "1" "3" "1"
  491. StrCmp $0 "" 0 strstradverror
  492. ${UnStrStrAdv} $0 "ABCabcabc" "abc" ">" "<" "1" "1" "1"
  493. StrCmp $0 "ABCabcabc" 0 strstradverror
  494. ${UnStrStrAdv} $0 "ABCabcabc" "abc" ">" "<" "0" "1" "1"
  495. StrCmp $0 "ABCabc" 0 strstradverror
  496. ${UnStrStrAdv} $0 "ABCabcabc" "abc" "<" "<" "1" "0" "1"
  497. StrCmp $0 "ABCabcabc" 0 strstradverror
  498. ${UnStrStrAdv} $0 "ABCabcabc" "abc" "<" "<" "0" "0" "1"
  499. StrCmp $0 "ABCabc" 0 strstradverror
  500. ${UnStrStrAdv} $0 "ABCabcabc" "abc" "<" ">" "0" "0" "1"
  501. StrCmp $0 "" 0 strstradverror
  502. ${UnStrStrAdv} $0 "ABCabcabc" "abc" "<" ">" "0" "1" "1"
  503. StrCmp $0 "abc" 0 strstradverror
  504. !insertmacro StackVerificationEnd
  505. !insertmacro EndStrFuncTest StrStrAdv
  506. # Test tokenizer
  507. !insertmacro StackVerificationStart
  508. ${UnStrTok} $0 "This is, or is not, just an example" " ," "4" "1"
  509. StrCmp $0 "not" 0 strtokerror
  510. ${UnStrTok} $0 "This is, or is not, just an example" " ," "4" "0"
  511. StrCmp $0 "is" 0 strtokerror
  512. ${UnStrTok} $0 "This is, or is not, just an example" " ," "152" "0"
  513. StrCmp $0 "" 0 strtokerror
  514. ${UnStrTok} $0 "This is, or is not, just an example" " ," "" "0"
  515. StrCmp $0 "example" 0 strtokerror
  516. ${UnStrTok} $0 "This is, or is not, just an example" " ," "L" "0"
  517. StrCmp $0 "example" 0 strtokerror
  518. ${UnStrTok} $0 "This is, or is not, just an example" " ," "0" "0"
  519. StrCmp $0 "This" 0 strtokerror
  520. !insertmacro StackVerificationEnd
  521. !insertmacro EndStrFuncTest StrTok
  522. # Test trim new lines
  523. !insertmacro StackVerificationStart
  524. ${UnStrTrimNewLines} $0 "$\r$\ntest$\r$\ntest$\r$\n"
  525. StrCmp $0 "$\r$\ntest$\r$\ntest" 0 strtrimnewlineserror
  526. !insertmacro StackVerificationEnd
  527. !insertmacro EndStrFuncTest StrTrimNewLines
  528. !insertmacro CompletedAllTests
  529. SectionEnd