#!/bin/bash

. ./common.lib_v0.22

p2s "common.lib loaded\n"

myDebugTest() {
	myDebug 5 "myDebugTest(${@})"
	p2s "myDebugTest: this is the test line"
	myDebug 6 "myDebugTest(${@})=..."
}

#F01.01
p2s "\E[04;30m#F01.01\E[0;m"
p2s "p2s: \E[01;31mto be tested\E[0m"
p2s "p2s: this is the test line"
p2s "p2s: \E[01;32mtest passed\E[0m\n"

#F01.02
p2s "\E[04;30m#F01.02\E[0;m"
p2s "p2st: \E[01;31mto be tested\E[0m"
p2st "p2st: this is the test line"
p2s "p2st: \E[01;32mtest passed\E[0m\n"

#F01.03
p2s "\E[04;30m#F01.03\E[0;m"
p2s "opps: \E[01;31mto be tested\E[0m"
p2s "oops: test to be define"
p2s "oops: \E[01;32mtest passed\E[0m\n"

#F01.04
p2s "\E[04;30m#F01.04\E[0;m"
p2s "oopst: \E[01;31mto be tested\E[0m"
p2s "oopst: test to be define"
p2s "oopst: \E[01;32mtest passed\E[0m\n"

#F01.05
p2s "\E[04;30m#F01.05\E[0;m"
p2s "myDebug: \E[01;31mto be tested\E[0m"
p2s "myDebug: Debug value ${DEBUG}"
myDebugTest
F01DEBUG=5
p2s "myDebug: Debug value ${DEBUG}"
myDebugTest
F01DEBUG=6
p2s "myDebug: Debug value ${DEBUG}"
myDebugTest
F01DEBUG=0
p2s "myDebug: Debug value ${DEBUG}"
myDebugTest
p2s "myDebug: \E[01;32mtest passed\E[0m\n"

#F01.06
p2s "\E[04;30m#F01.06\E[0;m"
p2s "myError: \E[01;31mto be tested\E[0m"
myError "this is the test line"
p2s "myError: __lastError=${__lastError}"
p2s "myError: __allError=${__allError}"
sleep 1
myError "this is the second test line"
p2s "myError: __lastError=${__lastError}"
p2s "myError: __allError=${__allError}"
p2s "myError: \E[01;32mtest passed\E[0m\n"

#F01.08
p2s "\E[04;30m#F01.08\E[0;m"
p2s "fileCreate: \E[01;31mto be tested\E[0m"
fileCreate
p2s "result: [${?}] - lastError: [${__lastError}]"
p2s "fileCreate: /tmp/filePipo.good"
fileCreate '/tmp/filePipo.good'
p2s "result: [${?}] - lastError: [${__lastError}]"
p2s "fileCreate: \E[01;32mtest passed\E[0m\n"

#F01.07
p2s "\E[04;30m#F01.07\E[0;m"
p2s "fileCheck: \E[01;31mto be tested\E[0m"
p2s "fileCheck: Empty file"
fileCheck
p2s "result: [${?}] - lastError: [${__lastError}]"
p2s "fileCheck: unknown file"
fileCheck '/tmp/filePipo.pipo' 755
p2s "result: [${?}] - lastError: [${__lastError}]"
p2s "fileCheck: Not good rights"
fileCheck '/tmp/filePipo.good' 755
p2s "result: [${?}] - lastError: [${__lastError}]"
p2s "fileCheck: OK"
fileCheck '/tmp/filePipo.good' 644
p2s "result: [${?}] - lastError: [${__lastError}]"
p2s "fileCheck: \E[01;32mtest passed\E[0m\n"

#F01.09
p2s "\E[04;30m#F01.09\E[0;m"
p2s "fileDelete: \E[01;31mto be tested\E[0m"
fileDelete
p2s "result: [${?}] - lastError: [${__lastError}]"
p2s "fileDelete: /tmp/filePipo.pipo"
fileDelete '/tmp/filePipo.pipo'
p2s "result: [${?}] - lastError: [${__lastError}]"
p2s "fileDelete: /tmp/filePipo.good"
fileDelete '/tmp/filePipo.good'
p2s "result: [${?}] - lastError: [${__lastError}]"
p2s "fileDelete: \E[01;32mtest passed\E[0m\n"

#F01.10
p2s "\E[04;30m#F01.10\E[0;m"
p2s "iniGetValue: \E[01;31mto be tested\E[0m"
p2s "iniGetValue: Empty file"
iniGetValue
p2s "result: [${?}] - lastError: [${__lastError}]"
p2s "iniGetValue: Non existant or commanted value"
iniGetValue "./test_common-lib.conf" "iniToto"
p2s "result: [${?}] - __iniGetValue: [${__iniGetValue}] - lastError: [${__lastError}]"
p2s "iniGetValue: Same multiple variable"
iniGetValue "./test_common-lib.conf" "iniTata"
p2s "result: [${?}] - __iniGetValue: [${__iniGetValue}] - lastError: [${__lastError}]"
p2s "iniGetValue: OK"
iniGetValue "./test_common-lib.conf" "iniTiti"
p2s "result: [${?}] - __iniGetValue: [${__iniGetValue}] - iniTiti: ${iniTiti} - lastError: [${__lastError}]"
p2s "iniGetValue: OK with setting the variable"
iniGetValue "./test_common-lib.conf" "iniTiti" 1
p2s "result: [${?}] - __iniGetValue: [${__iniGetValue}] - iniTiti: ${iniTiti} - lastError: [${__lastError}]"
p2s "iniGetValue: \E[01;32mtest passed\E[0m\n"

#F01.11
p2s "\E[04;30m#F01.11\E[0;m"
p2s "iniParseFile: \E[01;31mto be tested\E[0m"
p2s "iniParseFile: Empty file"
iniParseFile
p2s "result: [${?}] - lastError: [${__lastError}]"
p2s "iniParseFile: ./test_common-lib.conf"
iniParseFile "./test_common-lib.conf"
p2s "result: [${?}] - lastError: [${__lastError}]"
p2s "iniParseFile: isiTata: [${iniTata}] ... __T: [${__T}] ... __Ursulla: [${__Ursulla}]"
p2s "iniParseFile: \E[01;32mtest passed\E[0m\n"

#F01.12
p2s "\E[04;30m#F01.12\E[0;m"
p2s "trim: \E[01;31mto be tested\E[0m"
p2s "trim: '      test line\\\t      '"
trim '      test line	      '
p2s "result: [${?}] - __trim: [${__trim}]"
p2s "trim: \E[01;32mtest passed\E[0m\n"

#F01.13
p2s "\E[04;30m#F01.13\E[0;m"
p2s "logRotate: \E[01;31mto be tested\E[0m"
p2s "logRotate: \E[01;32mtest passed\E[0m\n"

#F01.14
p2s "\E[04;30m#F01.14\E[0;m"
export __logFileSize=10
p2s "logMe: \E[01;31mto be tested\E[0m"
logMe "logMe: this is the test line"
logMe "logMe: this is the second test line"
logMe "logMe: this is the third test line"
p2s "logMe: \E[01;32mtest passed\E[0m\n"

#F01.15
p2s "\E[04;30m#F01.15\E[0;m"
p2s "logMeV: \E[01;31mto be tested\E[0m"
logMeV "logMeV: this is the test line"
p2s "logMeV: \E[01;32mtest passed\E[0m\n"

#F01.16
p2s "\E[04;30m#F01.16\E[0;m"
p2s "isFunction: \E[01;31mto be tested\E[0m"
p2s "isFunction: isFunction(toto)"
isFunction "toto"
p2s "isFunction: isFunction(toto)=${?}"
p2s "isFunction: isFunction(F01Version)"
isFunction "F01Version"
p2s "isFunction: isFunction(F01Version)=${?}"
p2s "isFunction: isFunction(perl)"
isFunction "perl"
p2s "isFunction: isFunction(perl)=${?}"
p2s "isFunction: isFunction(perl, 1)"
isFunction "perl" 1
p2s "isFunction: isFunction(perl, 1)=${?}"
p2s "isFunction: \E[01;32mtest passed\E[0m\n"

#F01.17
p2s "\E[04;30m#F01.17\E[0;m"
p2s "spritnf: \E[01;31mto be tested\E[0m"
text1="my %s trut %s smells %s"
text2="big"
text3="never ever"
text4="like %s spirit..."
text5="teen"
echo "sprintf: text1='${text1}'"
p2s "sprintf: text2='${text2}'"
p2s "sprintf: text3='${text3}'"
echo "sprintf: text4='${text4}'"
p2s "sprintf: text5='${text5}'"
p2s "sprintf: sprintf(text1 text2 text3 text4 text5)"
#export F01DEBUG=5
sprintf "${text1}" "${text2}" "${text3}" "${text4}" "${text5}"
p2s "sprintf: sprintf(text1 text2 text3 text4 text5)=${__sprintf}"
p2s "sprintf: \E[01;32mtest passed\E[0m\n"

#F01.18
p2s "\E[04;30m#F01.18\E[0;m"
p2s "ltrim: \E[01;31mto be tested\E[0m"
p2s "ltrim: '      test line\\\t      '"
ltrim '      test line	      '
p2s "result: [${?}] - __ltrim: [${__ltrim}]"
p2s "ltrim: \E[01;32mtest passed\E[0m\n"

#F01.19
p2s "\E[04;30m#F01.19\E[0;m"
p2s "rtrim: \E[01;31mto be tested\E[0m"
p2s "rtrim: '      test line\\\t      '"
rtrim '      test line	      '
p2s "result: [${?}] - __rtrim: [${__rtrim}]"
p2s "rtrim: \E[01;32mtest passed\E[0m\n"



#F01.99
p2s "\E[04;30m#F01.99\E[0;m"
sleep 1
p2s "F01Version: \E[01;31mto be tested\E[0m"
F01Version 1
p2s "result: [${?}] - __F01Version: [${__F01Version}]"
F01Version
p2s "F01Version: \E[01;32mtest passed\E[0m\n"



