home *** CD-ROM | disk | FTP | other *** search
/ Chip 2004 March / CMCD0304.ISO / Software / Freeware / Programare / nullsoft / nsis20.exe / Examples / StrFunc.nsi < prev    next >
Text File  |  2004-02-07  |  7KB  |  212 lines

  1. Name "NSIS StrFunc Example"
  2. OutFile "StrFunc.exe"
  3. ShowInstDetails show
  4.  
  5. !include "StrFunc.nsh"
  6.  
  7. # declare used functions
  8. ${StrClbGet}
  9. ${StrClbSet}
  10. ${StrIOToNSIS}
  11. ${StrLoc}
  12. ${StrLowerCase}
  13. ${StrNSISToIO}
  14. ${StrRep}
  15. ${StrStr}
  16. ${StrStrAdv}
  17. ${StrTok}
  18. ${StrTrimNewLines}
  19. ${StrUpperCase}
  20. ${StrSort}
  21.  
  22. Section
  23.  
  24.   # test clipboard functions
  25.   ${StrClbSet} "StrFunc clipboard test"
  26.   ${StrClbGet} $0
  27.   StrCmp $0 "StrFunc clipboard test" +3
  28.     DetailPrint "FAILED StrClbGet/StrClbSet test"
  29.     Goto +2
  30.     DetailPrint "PASSED StrClbGet/StrClbSet test"
  31.  
  32.   # test IO functions
  33.   !macro testio str
  34.   ${StrNSISToIO} $0 "${str}"
  35.   ${StrIOToNSIS} $0 $0
  36.   StrCmp $0 "${str}" 0 ioerror
  37.   !macroend
  38.   !insertmacro testio "$\rtest$\n"
  39.   !insertmacro testio "test$\n"
  40.   !insertmacro testio "$\rtest"
  41.   !insertmacro testio "test"
  42.   !insertmacro testio "$\r\$\t$\n"
  43.   !insertmacro testio "$\r \ $\t $\n $$"
  44.   !insertmacro testio ""
  45.   !insertmacro testio " "
  46.   DetailPrint "PASSED StrNSISToIO/StrIOToNSIS test"
  47.   Goto +2
  48. ioerror:
  49.   DetailPrint "FAILED StrNSISToIO/StrIOToNSIS test"
  50.  
  51.   # test string search functions
  52.   ${StrLoc} $0 "This is just an example" "just" "<"
  53.   StrCmp $0 "11" 0 strlocerror
  54.   ${StrLoc} $0 a abc <
  55.   StrCmp $0 "" 0 strlocerror
  56.   ${StrLoc} $0 a abc >
  57.   StrCmp $0 "" 0 strlocerror
  58.   ${StrLoc} $0 abc a >
  59.   StrCmp $0 "0" 0 strlocerror
  60.   ${StrLoc} $0 abc b >
  61.   StrCmp $0 "1" 0 strlocerror
  62.   ${StrLoc} $0 abc c >
  63.   StrCmp $0 "2" 0 strlocerror
  64.   ${StrLoc} $0 abc a <
  65.   StrCmp $0 "2" 0 strlocerror
  66.   ${StrLoc} $0 abc b <
  67.   StrCmp $0 "1" 0 strlocerror
  68.   ${StrLoc} $0 abc c <
  69.   StrCmp $0 "0" 0 strlocerror
  70.   ${StrLoc} $0 abc d <
  71.   StrCmp $0 "" 0 strlocerror
  72.   DetailPrint "PASSED StrLoc test"
  73.   Goto +2
  74. strlocerror:
  75.   DetailPrint "FAILED StrLoc test"
  76.  
  77.   ${StrStr} $0 "abcefghijklmnopqrstuvwxyz" "g"
  78.   StrCmp $0 "ghijklmnopqrstuvwxyz" 0 strstrerror
  79.   ${StrStr} $0 "abcefghijklmnopqrstuvwxyz" "ga"
  80.   StrCmp $0 "" 0 strstrerror
  81.   ${StrStr} $0 "abcefghijklmnopqrstuvwxyz" ""
  82.   StrCmp $0 "abcefghijklmnopqrstuvwxyz" 0 strstrerror
  83.   ${StrStr} $0 "a" "abcefghijklmnopqrstuvwxyz"
  84.   StrCmp $0 "" 0 strstrerror
  85.   DetailPrint "PASSED StrStr test"
  86.   Goto +2
  87. strstrerror:
  88.   DetailPrint "FAILED StrStr test"
  89.  
  90.   ${StrStrAdv} $0 "abcabcabc" "a" ">" ">" "1" "0"
  91.   StrCmp $0 "abcabcabc" 0 strstradverror
  92.   ${StrStrAdv} $0 "abcabcabc" "a" ">" ">" "1" "1"
  93.   StrCmp $0 "abcabc" 0 strstradverror
  94.   ${StrStrAdv} $0 "abcabcabc" "a" ">" ">" "1" "2"
  95.   StrCmp $0 "abc" 0 strstradverror
  96.   ${StrStrAdv} $0 "abcabcabc" "a" ">" ">" "1" "3"
  97.   StrCmp $0 "" 0 strstradverror
  98.   ${StrStrAdv} $0 "abcabcabc" "abc" ">" "<" "1" "1"
  99.   StrCmp $0 "abcabc" 0 strstradverror
  100.   ${StrStrAdv} $0 "abcabcabc" "abc" ">" "<" "0" "1"
  101.   StrCmp $0 "abcabc" 0 strstradverror
  102.   ${StrStrAdv} $0 "abcabcabc" "abc" "<" "<" "1" "0"
  103.   StrCmp $0 "abcabcabc" 0 strstradverror
  104.   ${StrStrAdv} $0 "abcabcabc" "abc" "<" "<" "0" "0"
  105.   StrCmp $0 "abcabc" 0 strstradverror
  106.   ${StrStrAdv} $0 "abcabcabc" "abc" "<" ">" "0" "0"
  107.   StrCmp $0 "" 0 strstradverror
  108.   ${StrStrAdv} $0 "abcabcabc" "abc" "<" ">" "0" "1"
  109.   StrCmp $0 "abc" 0 strstradverror
  110.   DetailPrint "PASSED StrStrAdv test"
  111.   Goto +2
  112. strstradverror:
  113.   DetailPrint "FAILED StrStrAdv test"
  114.  
  115.   # test string replacement
  116.   ${StrRep} $0 "This is just an example" "an" "one"
  117.   StrCmp $0 "This is just one example" 0 strreperror
  118.   ${StrRep} $0 "test... test... 1 2 3..." "test" "testing"
  119.   StrCmp $0 "testing... testing... 1 2 3..." 0 strreperror
  120.   ${StrRep} $0 "" "test" "testing"
  121.   StrCmp $0 "" 0 strreperror
  122.   ${StrRep} $0 "test" "test" "testing"
  123.   StrCmp $0 "testing" 0 strreperror
  124.   ${StrRep} $0 "test" "test" ""
  125.   StrCmp $0 "" 0 strreperror
  126.   ${StrRep} $0 "test" "" "abc"
  127.   StrCmp $0 "test" 0 strreperror
  128.   ${StrRep} $0 "test" "" ""
  129.   StrCmp $0 "test" 0 strreperror
  130.   DetailPrint "PASSED StrRep test"
  131.   Goto +2
  132. strreperror:
  133.   DetailPrint "FAILED StrRep test"
  134.  
  135.   # test sorting
  136.   ${StrSort} $0 "This is just an example" " just" "" "ple" "0" "0"
  137.   StrCmp $0 "This is an exam" 0 strsorterror
  138.   ${StrSort} $0 "This is just an example" "j" " " " " "0" "1"
  139.   StrCmp $0 "just" 0 strsorterror
  140.   ${StrSort} $0 "This is just an example" "j" "" "" "0" "1"
  141.   StrCmp $0 "This is just an example" 0 strsorterror
  142.   ${StrSort} $0 "This is just an example" "us" " " "" "0" "1"
  143.   StrCmp $0 "just an example" 0 strsorterror
  144.   ${StrSort} $0 "This is just an example" "u" "" " " "0" "1"
  145.   StrCmp $0 "This is just" 0 strsorterror
  146.   ${StrSort} $0 "This is just an example" "just" " " " " "0" "1"
  147.   StrCmp $0 "just" 0 strsorterror
  148.   ${StrSort} $0 "This is just an example" "t" " " " " "0" "1"
  149.   StrCmp $0 "This" 0 strsorterror
  150.   ${StrSort} $0 "This is just an example" "le" " " " " "0" "1"
  151.   StrCmp $0 "example" 0 strsorterror
  152.   ${StrSort} $0 "This is just an example" "le" " " " " "1" "0"
  153.   StrCmp $0 " examp" 0 strsorterror
  154.   ${StrSort} $0 "an error has occured" "e" " " " " "0" "1"
  155.   StrCmp $0 "error" 0 strsorterror
  156.   ${StrSort} $0 "" "something" " " " " "0" "1"
  157.   StrCmp $0 "" 0 strsorterror
  158.   ${StrSort} $0 "This is just an example" "j" " " " " "1" "1"
  159.   StrCmp $0 " just " 0 strsorterror
  160.   ${StrSort} $0 "This is just an example" "j" " " " " "1" "0"
  161.   StrCmp $0 " ust " 0 strsorterror
  162.   ${StrSort} $0 "This is just an example" "j" "" "" "1" "0"
  163.   StrCmp $0 "This is ust an example" 0 strsorterror
  164.   ${StrSort} $0 "This is just an example" "us" " " "" "1" "0"
  165.   StrCmp $0 " jt an example" 0 strsorterror
  166.   ${StrSort} $0 "This is just an example" "u" "" " " "1" "0"
  167.   StrCmp $0 "This is jst " 0 strsorterror
  168.   ${StrSort} $0 "This is just an example" "just" " " " " "1" "0"
  169.   StrCmp $0 "  " 0 strsorterror
  170.   ${StrSort} $0 "an error has occured" "e" " " " " "1" "0"
  171.   StrCmp $0 " rror " 0 strsorterror
  172.   ${StrSort} $0 "" "something" " " " " "1" "0"
  173.   StrCmp $0 "" 0 strsorterror
  174.   DetailPrint "PASSED StrSort test"
  175.   Goto +2
  176. strsorterror:
  177.   DetailPrint "FAILED StrSort test"
  178.  
  179.   # test lower/upper case
  180.   ${StrLowerCase} $0 "abcefghijklmnopqrstuvwxyz"
  181.   ${StrUpperCase} $0 $0
  182.   StrCmp $0 "abcefghijklmnopqrstuvwxyz" +3
  183.     DetailPrint "FAILED StrLowerCase/StrUpperCase test"
  184.     Goto +2
  185.     DetailPrint "PASSED StrLowerCase/StrUpperCase test"
  186.  
  187.   # test tokenizer
  188.   ${StrTok} $0 "This is, or is not, just an example" " ," "5" "1"
  189.   StrCmp $0 "not" 0 strtokerror
  190.   ${StrTok} $0 "This is, or is not, just an example" " ," "5" "0"
  191.   StrCmp $0 "is" 0 strtokerror
  192.   ${StrTok} $0 "This is, or is not, just an example" " ," "152" "0"
  193.   StrCmp $0 "" 0 strtokerror
  194.   ${StrTok} $0 "This is, or is not, just an example" " ," "0" "0"
  195.   StrCmp $0 "example" 0 strtokerror
  196.   ${StrTok} $0 "This is, or is not, just an example" " ," "-1" "0"
  197.   StrCmp $0 "example" 0 strtokerror
  198.   ${StrTok} $0 "This is, or is not, just an example" " ," "1" "0"
  199.   StrCmp $0 "This" 0 strtokerror
  200.   DetailPrint "PASSED StrTok test"
  201.   Goto +2
  202. strtokerror:
  203.   DetailPrint "FAILED StrTok test"
  204.  
  205.   # test trim new lines
  206.   ${StrTrimNewLines} $0 "$\r$\ntest$\r$\ntest$\r$\n"
  207.   StrCmp $0 "$\r$\ntest$\r$\ntest" +3
  208.     DetailPrint "FAILED StrTrimNewLines test"
  209.     Goto +2
  210.     DetailPrint "PASSED StrTrimNewLines test"
  211.  
  212. SectionEnd