StrFunc.nsi 22 KB

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