cmake_minimum_required(VERSION 2.8)
project(pkcs11_tests)

include_directories(
	${CMAKE_CURRENT_SOURCE_DIR}/include 
	${CMAKE_CURRENT_SOURCE_DIR}/common
	${CMAKE_CURRENT_SOURCE_DIR}
)

function(compile_tool)
    add_executable(${ARGV0} 
		${ARGN}
		${CMAKE_CURRENT_SOURCE_DIR}/common/test_common.h
		${CMAKE_CURRENT_SOURCE_DIR}/common/test_common.c
		${CMAKE_CURRENT_SOURCE_DIR}/include/pkcs11t_gost.h
		${CMAKE_CURRENT_SOURCE_DIR}/include/pkcs11.h
		${CMAKE_CURRENT_SOURCE_DIR}/include/pkcs11t.h
		${CMAKE_CURRENT_SOURCE_DIR}/include/pkcs11f.h
	)
	if (WIN32)
		set_target_properties(${ARGV0}
			PROPERTIES
				COMPILE_FLAGS 
					"-DPKCS11_API_PATH=${PKCS11_API_PATH} -DUSER_PIN=${USER_PIN} -DSO_PIN=${SO_PIN}"
		)
	else (WIN32)
		set_target_properties(${ARGV0}
			PROPERTIES
				COMPILE_FLAGS 
					"-DPKCS11_API_PATH=${PKCS11_API_PATH} -DUSER_PIN=${USER_PIN} -DSO_PIN=${SO_PIN} -pthread"
		)
		target_link_libraries(${ARGV0} pthread dl)
	endif (WIN32)
endfunction(compile_tool)

function(compile_test)
	compile_tool(${ARGN})
	add_test(${ARGV0} 
		${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${ARGV0}
		-api ${PKCS11_API_PATH} -user_pin ${USER_PIN}
	)
endfunction(compile_test)

compile_tool(init_token init_token.c)
compile_tool(threadmkobj threadmkobj.c)
compile_tool(long_testing long_testing.c long_ckm_gostr3410_512.c)
compile_tool(cka_sensitive cka_sensitive.c)

# В тестах предполагается, что токен 
# полностью подготовлен к прикладной работе.
compile_test(info info.c)
compile_test(cko_data cko_data.c)
compile_test(cko_certificate cko_certificate.c)
compile_test(ckm_gostr3411 ckm_gostr3411.c)
compile_test(ckm_gostr3411_12_256 ckm_gostr3411_12_256.c)
compile_test(ckm_gostr3411_12_512 ckm_gostr3411_12_512.c)
compile_test(ckm_gostr3411_hmac ckm_gostr3411_hmac.c)
compile_test(ckm_gostr3411_12_256_hmac ckm_gostr3411_12_256_hmac.c)
compile_test(ckm_gostr3411_12_512_hmac ckm_gostr3411_12_512_hmac.c)
compile_test(ckm_kdf_gostr3411_2012_256 ckm_kdf_gostr3411_2012_256.c)
compile_test(ckm_kdf_tree_gostr3411_2012_256 ckm_kdf_tree_gostr3411_2012_256.c)
compile_test(ckm_gost_generic_secret_key_gen ckm_gost_generic_secret_key_gen.c)
compile_test(ckm_extract_key_from_key ckm_extract_key_from_key.c)
compile_test(ckm_gost_cipher_key_gen ckm_gost_cipher_key_gen.c)
compile_test(ckm_gost_cipher_ecb ckm_gost_cipher_ecb.c)
compile_test(ckm_gost_cipher_cbc ckm_gost_cipher_cbc.c)
compile_test(ckm_gost_cipher_ctr ckm_gost_cipher_ctr.c)
compile_test(ckm_gost_cipher_ofb ckm_gost_cipher_ofb.c)
compile_test(ckm_gost_cipher_cfb ckm_gost_cipher_cfb.c)
compile_test(ckm_gost_cipher_acpkm_ctr ckm_gost_cipher_acpkm_ctr.c)
compile_test(ckm_gost_cipher_omac ckm_gost_cipher_omac.c)
compile_test(ckm_gost_cipher_acpkm_omac ckm_gost_cipher_acpkm_omac.c)
compile_test(ckm_gost_cipher_key_wrap ckm_gost_cipher_key_wrap.c)
compile_test(ckm_gost_cipher_pkcs8_key_wrap ckm_gost_cipher_pkcs8_key_wrap.c)
compile_test(ckm_gost28147_key_gen ckm_gost28147_key_gen.c)
compile_test(ckm_gost28147 ckm_gost28147.c)
compile_test(ckm_gost28147_ecb ckm_gost28147_ecb.c)
compile_test(ckm_gost28147_ecb_mac_wrap ckm_gost28147_ecb_mac_wrap.c)
compile_test(ckm_gost28147_cnt ckm_gost28147_cnt.c)
compile_test(ckm_gost28147_cbc ckm_gost28147_cbc.c)
compile_test(ckm_gost28147_mac ckm_gost28147_mac.c)
compile_test(ckm_gost28147_cfb_random ckm_gost28147_cfb_random.c)
compile_test(ckm_gost28147_key_wrap ckm_gost28147_key_wrap.c)
compile_test(ckm_gost28147_pkcs8_key_wrap ckm_gost28147_pkcs8_key_wrap.c)
compile_test(ckm_kdf_4357 ckm_kdf_4357.c)
compile_test(ckm_magma_key_gen ckm_magma_key_gen.c)
compile_test(ckm_magma_ecb ckm_magma_ecb.c)
compile_test(ckm_magma_cbc ckm_magma_cbc.c)
compile_test(ckm_magma_ctr ckm_magma_ctr.c)
compile_test(ckm_magma_acpkm_ctr ckm_magma_acpkm_ctr.c)
compile_test(ckm_magma_ofb ckm_magma_ofb.c)
compile_test(ckm_magma_cfb ckm_magma_cfb.c)
compile_test(ckm_magma_omac ckm_magma_omac.c)
compile_test(ckm_magma_acpkm_omac ckm_magma_acpkm_omac.c)
compile_test(ckm_magma_key_wrap ckm_magma_key_wrap.c)
compile_test(ckm_magma_cfb_errors ckm_magma_cfb_errors.c)
compile_test(ckm_magma_cfb_random ckm_magma_cfb_random.c)
compile_test(ckm_kuznyechik_key_gen ckm_kuznyechik_key_gen.c)
compile_test(ckm_kuznyechik_ecb ckm_kuznyechik_ecb.c)
compile_test(ckm_kuznyechik_cbc ckm_kuznyechik_cbc.c)
compile_test(ckm_kuznyechik_ctr ckm_kuznyechik_ctr.c)
compile_test(ckm_kuznyechik_acpkm_ctr ckm_kuznyechik_acpkm_ctr.c)
compile_test(ckm_kuznyechik_ofb ckm_kuznyechik_ofb.c)
compile_test(ckm_kuznyechik_cfb ckm_kuznyechik_cfb.c)
compile_test(ckm_kuznyechik_omac ckm_kuznyechik_omac.c)
compile_test(ckm_kuznyechik_acpkm_omac ckm_kuznyechik_acpkm_omac.c)
compile_test(ckm_kuznyechik_key_wrap ckm_kuznyechik_key_wrap.c)
compile_test(ckm_kuznyechik_cfb_random ckm_kuznyechik_cfb_random.c)
compile_test(ckm_gostr3410_key_pair_gen ckm_gostr3410_key_pair_gen.c)
compile_test(ckm_gostr3410_public_key_derive ckm_gostr3410_public_key_derive.c)
compile_test(ckm_gostr3410 ckm_gostr3410.c)
compile_test(ckm_gostr3410_512 ckm_gostr3410_512.c)
compile_test(ckm_gostr3410_key_derive ckm_gostr3410_key_derive.c)
compile_test(ckm_gostr3410_12_256_key_derive ckm_gostr3410_12_256_key_derive.c)
compile_test(ckm_gostr3410_12_512_key_derive ckm_gostr3410_12_512_key_derive.c)
compile_test(ckm_gostr3410_2012_256_vko_256 ckm_gostr3410_2012_256_vko_256.c)
compile_test(ckm_gostr3410_2012_512_vko_256 ckm_gostr3410_2012_512_vko_256.c)
compile_test(ckm_gostr3410_2012_512_vko_512 ckm_gostr3410_2012_512_vko_512.c)
compile_test(ckm_gostr3410_key_wrap ckm_gostr3410_key_wrap.c)
compile_test(ckm_gostr3410_with_gostr3411 ckm_gostr3410_with_gostr3411.c)
compile_test(ckm_gostr3410_with_gostr3411_12_256 ckm_gostr3410_with_gostr3411_12_256.c)
compile_test(ckm_gostr3410_with_gostr3411_12_512 ckm_gostr3410_with_gostr3411_12_512.c)
compile_test(cka_always_authenticate cka_always_authenticate.c)
compile_test(keypair_import keypair_import.c)
# Deprecated in 2.40
compile_test(ckm_tls_gost_prf ckm_tls_gost_prf.c)
# Deprecated in 2.40
compile_test(ckm_tls_gost_prf_2012 ckm_tls_gost_prf_2012.c)
compile_test(ckm_tls_gost_pre_master_key_gen ckm_tls_gost_pre_master_key_gen.c)
compile_test(ckm_tls_gost_master_key_derive ckm_tls_gost_master_key_derive.c)
compile_test(ckm_tls_gost_key_and_mac_derive ckm_tls_gost_key_and_mac_derive.c)
compile_test(ckm_tls12_master_key_derive ckm_tls12_master_key_derive.c)
compile_test(ckm_tls12_key_and_mac_derive ckm_tls12_key_and_mac_derive.c)
compile_test(ckm_tls_mac ckm_tls_mac.c)
compile_test(ckm_tls_kdf ckm_tls_kdf.c)
compile_test(ckm_tls_tree_gostr3411_2012_256 ckm_tls_tree_gostr3411_2012_256.c)
compile_test(ckm_pkcs5_pbkd2 ckm_pkcs5_pbkd2.c)
compile_test(ckm_pba_gostr3411_with_gostr3411_hmac ckm_pba_gostr3411_with_gostr3411_hmac.c)
compile_test(create_obj create_obj.c)
