#
# this makefile can be used to run the language specific tests
# or stestlib alone
#
# tests for /bin/claes /bin/clkeys /bin/clsmime and /bin/cltls are included
# some tests require gpg2 and openssl
#
# 22 June 2026,  Ralf Senderek
#


R1 = "\\0033[1;31m"
R0 = "\\0033[0;39m"
G1 = "\\0033[1;32m"
G0 = "\\0033[0;39m"
O1 = "\\0033[1;33m"
O0 = "\\0033[0;39m"

RED    = echo  $(R1) $(1) $(R0)
GREEN  = echo  $(G1) $(1) $(G0)
ORANGE = echo  $(O1) $(1) $(O0) 

run = @$(1); RET=$$?; if [ $${RET} = 0 ]; then $(call GREEN, OK : $${RET}); else $(call RED, FAILED : exit code $${RET}); fi; echo


all:
	/bin/clear
	make ctest
	make pytest
	make pltest
	make javatest
	make toolstest

testlib:
	-$(call run, ./stestlib)

ctest:
	@$(call ORANGE, Running C tests ...\\n) 
	-$(call run, cd /lib/cryptlib/examples/c; make ; ./sha2-test; rm ./sha2-test)
	@echo "#------------------------------------------#"

pytest:
	@$(call ORANGE, Running PYTHON tests ...\\n) 
	@echo
	-$(call run, /bin/python3 ./python/python3-encrypt)
	@echo
	-$(call run, /bin/python3 ./python/python3-decrypt; rm ./outfile)
	$(call getexit, 0)
	@echo
	-$(call run, /bin/python3 ./python/python3-test)
	@echo
	@echo "#------------------------------------------#"

pltest:	
	@$(call ORANGE, Running PERL tests ...\\n) 
	@echo
	-$(call run, /bin/perl ./perl/ubuntu-perltest.pl)
	@echo
	@echo "#------------------------------------------#"

javatest:
	@$(call ORANGE, Running JAVA tests ...\\n) 
	@echo
	-$(call run, cd java; javac -cp /usr/share/java/cryptlib.jar encrypt.java ;  java  -cp /usr/share/java/cryptlib.jar:. --enable-native-access=ALL-UNNAMED encrypt)
	@echo
	-$(call run, cd java; javac -cp /usr/share/java/cryptlib.jar decrypt.java ;  java  -cp /usr/share/java/cryptlib.jar:. --enable-native-access=ALL-UNNAMED decrypt)
	cd java; rm ./outfile ; rm ./*.class
	@echo
	@echo "#------------------------------------------#"

toolstest:
	make claestest
	make clkeystest
	make clsmimetest
	make cltlstest

claestest:
	@/bin/mkdir -p claes
	@$(call ORANGE, Running tests on claes ...\\n) 
	@echo
	-$(call run, ./run_aes_tests)
	@echo
	@echo "#------------------------------------------#"


clkeystest:
	@/bin/mkdir -p clkeys
	@$(call ORANGE, Running tests on clkeys ...\\n) 
	@echo
	-$(call run, ./run_keys_tests)
	@echo
	@echo "#------------------------------------------#"

clsmimetest:
	@/bin/mkdir -p clsmime
	@$(call ORANGE, Running tests on clsmime ...\\n) 
	@echo
	-$(call run, ./run_smime_tests)
	@echo
	@echo "#------------------------------------------#"

cltlstest:
	@/bin/mkdir -p cltls
	@$(call ORANGE, Running tests on cltls ...\\n) 
	@echo
	-$(call run, ./run_tls_tests)
	@echo
	@echo "#------------------------------------------#"

cleantools:
	@echo
	@echo "ls -l toolstest/claes"
	@/bin/rm -f claes/bsd* claes/gpg* claes/ossl* claes/huge* claes/16* claes/18* claes/83*; /bin/ls -l claes
	@echo
	@echo "ls -l toolstest/clkeys"
	@/bin/rm -f clkeys/test* clkeys/J* clkeys/P* clkeys/CA* ; /bin/ls -l clkeys
	@echo
	@echo "ls -l toolstest/clsmime"
	@/bin/rm -f clsmime/bsd* clsmime/J* clsmime/H* clsmime/test* clsmime/CA* clsmime/*SMIME 
	@/bin/rm -rf clsmime/peter clsmime/list.good clsmime/Tom* clsmime/EVO*
	@/bin/ls -l clsmime
	@echo
	@echo "ls -l toolstest/cltls"
	@/bin/rm -rf cltls/home cltls/*.com cltls/*.ie cltls/*.de cltls/www*
	@/bin/ls -l cltls
