aboutsummaryrefslogtreecommitdiffstats
path: root/src/tests
diff options
context:
space:
mode:
authorSimon Warta <[email protected]>2015-06-26 20:20:32 +0200
committerSimon Warta <[email protected]>2015-07-03 10:33:45 +0200
commitf472b8fc61accbbaa6a36af9d2d20b0fde37a1a2 (patch)
tree8e71c24da6f7f5b037024741105ca392369e590a /src/tests
parentcd9037e29f32197b9c37ef7bec955ac2372b543b (diff)
Make Botan compile when only some modules are enabled
Fixes #146.
Diffstat (limited to 'src/tests')
-rw-r--r--src/tests/test_aead.cpp8
-rw-r--r--src/tests/test_bigint.cpp15
-rw-r--r--src/tests/test_c25519.cpp15
-rw-r--r--src/tests/test_compression.cpp9
-rw-r--r--src/tests/test_cvc.cpp16
-rw-r--r--src/tests/test_dh.cpp11
-rw-r--r--src/tests/test_dlies.cpp25
-rw-r--r--src/tests/test_dsa.cpp10
-rw-r--r--src/tests/test_ecc_pointmul.cpp75
-rw-r--r--src/tests/test_ecdsa.cpp60
-rw-r--r--src/tests/test_elg.cpp24
-rw-r--r--src/tests/test_gost_3410.cpp11
-rw-r--r--src/tests/test_kdf.cpp8
-rw-r--r--src/tests/test_mac.cpp8
-rw-r--r--src/tests/test_mceliece.cpp8
-rw-r--r--src/tests/test_modes.cpp16
-rw-r--r--src/tests/test_nr.cpp20
-rw-r--r--src/tests/test_ocb.cpp21
-rw-r--r--src/tests/test_pbkdf.cpp8
-rw-r--r--src/tests/test_pubkey.cpp19
-rw-r--r--src/tests/test_rsa.cpp8
-rw-r--r--src/tests/test_rw.cpp20
-rw-r--r--src/tests/test_srp6.cpp9
-rw-r--r--src/tests/test_stream.cpp8
-rw-r--r--src/tests/test_tss.cpp15
-rw-r--r--src/tests/tests.h30
-rw-r--r--src/tests/unit_ecc.cpp16
-rw-r--r--src/tests/unit_ecdsa.cpp17
-rw-r--r--src/tests/unit_x509.cpp29
29 files changed, 375 insertions, 164 deletions
diff --git a/src/tests/test_aead.cpp b/src/tests/test_aead.cpp
index e9f002e19..603fdc1b0 100644
--- a/src/tests/test_aead.cpp
+++ b/src/tests/test_aead.cpp
@@ -6,6 +6,8 @@
#include "tests.h"
+#if defined(BOTAN_HAS_AEAD_MODES)
+
#include <botan/hex.h>
#include <botan/aead.h>
#include <iostream>
@@ -143,3 +145,9 @@ size_t test_aead()
return run_tests_in_dir(TEST_DATA_DIR "aead", test);
}
+
+#else
+
+SKIP_TEST(aead);
+
+#endif // BOTAN_HAS_AEAD_MODES
diff --git a/src/tests/test_bigint.cpp b/src/tests/test_bigint.cpp
index 3cf403743..f6ae2a654 100644
--- a/src/tests/test_bigint.cpp
+++ b/src/tests/test_bigint.cpp
@@ -6,6 +6,10 @@
#include "tests.h"
+#if defined(BOTAN_HAS_BIGINT)
+
+#if defined(BOTAN_HAS_NUMBERTHEORY)
+
#include <vector>
#include <string>
#include <fstream>
@@ -380,3 +384,14 @@ size_t test_bigint()
return total_errors;
}
+#else
+
+UNTESTED_WARNING(bigint);
+
+#endif // BOTAN_HAS_NUMBERTHEORY
+
+#else
+
+SKIP_TEST(bigint);
+
+#endif // BOTAN_HAS_BIGINT
diff --git a/src/tests/test_c25519.cpp b/src/tests/test_c25519.cpp
index 46d9c1bea..aa34a5fc1 100644
--- a/src/tests/test_c25519.cpp
+++ b/src/tests/test_c25519.cpp
@@ -5,19 +5,18 @@
*/
#include "tests.h"
-#include "test_pubkey.h"
#if defined(BOTAN_HAS_CURVE_25519)
+
+#include "test_pubkey.h"
+
#include <botan/curve25519.h>
#include <botan/hex.h>
#include <iostream>
#include <fstream>
-#endif
using namespace Botan;
-#if defined(BOTAN_HAS_CURVE_25519)
-
namespace {
size_t curve25519_scalar_kat(const std::string& secret_h,
@@ -41,13 +40,11 @@ size_t curve25519_scalar_kat(const std::string& secret_h,
}
}
-#endif
size_t test_curve25519()
{
size_t fails = 0;
-#if defined(BOTAN_HAS_CURVE_25519)
std::ifstream c25519_scalar(PK_TEST_DATA_DIR "/c25519_scalar.vec");
fails += run_tests_bb(c25519_scalar, "Curve25519 ScalarMult", "Out", true,
@@ -55,8 +52,12 @@ size_t test_curve25519()
{
return curve25519_scalar_kat(m["Secret"], m["Basepoint"], m["Out"]);
});
-#endif
return fails;
}
+#else
+
+SKIP_TEST(curve25519);
+
+#endif // BOTAN_HAS_CURVE_25519
diff --git a/src/tests/test_compression.cpp b/src/tests/test_compression.cpp
index 9b83737a0..b68262385 100644
--- a/src/tests/test_compression.cpp
+++ b/src/tests/test_compression.cpp
@@ -1,4 +1,7 @@
#include "tests.h"
+
+#if defined(BOTAN_HAS_COMPRESSION)
+
#include <botan/compression.h>
#include <botan/hex.h>
#include <iostream>
@@ -123,3 +126,9 @@ size_t test_compression()
return fails;
}
+
+#else
+
+SKIP_TEST(compression);
+
+#endif // BOTAN_HAS_COMPRESSION
diff --git a/src/tests/test_cvc.cpp b/src/tests/test_cvc.cpp
index 9b11dea7c..f25775852 100644
--- a/src/tests/test_cvc.cpp
+++ b/src/tests/test_cvc.cpp
@@ -8,10 +8,11 @@
*/
#include "tests.h"
-#include <botan/build.h>
#if defined(BOTAN_HAS_CARD_VERIFIABLE_CERTIFICATES)
+#if defined(BOTAN_HAS_ECDSA) && defined(BOTAN_HAS_RSA)
+
#include <iosfwd>
#include <iostream>
#include <iterator>
@@ -571,6 +572,15 @@ size_t test_cvc()
return 0;
}
+
+#else
+
+UNTESTED_WARNING(cvc);
+
+#endif // BOTAN_HAS_ECDSA && BOTAN_HAS_RSA
+
#else
-size_t test_cvc() { return 0; }
-#endif
+
+SKIP_TEST(cvc);
+
+#endif // BOTAN_HAS_CARD_VERIFIABLE_CERTIFICATES
diff --git a/src/tests/test_dh.cpp b/src/tests/test_dh.cpp
index afafd222a..a546006a5 100644
--- a/src/tests/test_dh.cpp
+++ b/src/tests/test_dh.cpp
@@ -5,10 +5,11 @@
*/
#include "tests.h"
-#include "test_pubkey.h"
#if defined(BOTAN_HAS_DIFFIE_HELLMAN)
+#include "test_pubkey.h"
+
#include <botan/pubkey.h>
#include <botan/dh.h>
#include <botan/hex.h>
@@ -49,13 +50,11 @@ size_t dh_sig_kat(const std::string& p,
}
}
-#endif
size_t test_dh()
{
size_t fails = 0;
-#if defined(BOTAN_HAS_DIFFIE_HELLMAN)
std::ifstream dh_sig(PK_TEST_DATA_DIR "/dh.vec");
fails += run_tests_bb(dh_sig, "DH Kex", "K", true,
@@ -63,8 +62,12 @@ size_t test_dh()
{
return dh_sig_kat(m["P"], m["G"], m["X"], m["Y"], m["KDF"], m["OutLen"], m["K"]);
});
-#endif
return fails;
}
+#else
+
+SKIP_TEST(dh);
+
+#endif // BOTAN_HAS_DIFFIE_HELLMAN
diff --git a/src/tests/test_dlies.cpp b/src/tests/test_dlies.cpp
index ee37f33e2..8fc1f31a0 100644
--- a/src/tests/test_dlies.cpp
+++ b/src/tests/test_dlies.cpp
@@ -5,23 +5,22 @@
*/
#include "tests.h"
+
+#if defined(BOTAN_HAS_DLIES)
+
#include "test_pubkey.h"
-#include <botan/hex.h>
#include <iostream>
#include <fstream>
-#if defined(BOTAN_HAS_DLIES)
-
- #include <botan/pubkey.h>
- #include <botan/lookup.h>
- #include <botan/dlies.h>
- #include <botan/dh.h>
-#endif
+#include <botan/dlies.h>
+#include <botan/dh.h>
+#include <botan/hex.h>
+#include <botan/pubkey.h>
+#include <botan/lookup.h>
using namespace Botan;
-#if defined(BOTAN_HAS_DLIES)
namespace {
size_t dlies_kat(const std::string& p,
@@ -69,13 +68,11 @@ size_t dlies_kat(const std::string& p,
}
}
-#endif
size_t test_dlies()
{
size_t fails = 0;
-#if defined(BOTAN_HAS_DLIES)
std::ifstream dlies(PK_TEST_DATA_DIR "/dlies.vec");
fails += run_tests_bb(dlies, "DLIES Encryption", "Ciphertext", true,
@@ -83,8 +80,12 @@ size_t test_dlies()
{
return dlies_kat(m["P"], m["G"], m["X1"], m["X2"], m["Msg"], m["Ciphertext"]);
});
-#endif
return fails;
}
+#else
+
+SKIP_TEST(dlies);
+
+#endif // BOTAN_HAS_DLIES
diff --git a/src/tests/test_dsa.cpp b/src/tests/test_dsa.cpp
index b31bda9fe..9ce496d80 100644
--- a/src/tests/test_dsa.cpp
+++ b/src/tests/test_dsa.cpp
@@ -5,10 +5,10 @@
*/
#include "tests.h"
-#include "test_pubkey.h"
#if defined(BOTAN_HAS_DSA)
+#include "test_pubkey.h"
#include <botan/pubkey.h>
#include <botan/dsa.h>
@@ -47,13 +47,11 @@ size_t dsa_sig_kat(const std::string& p,
}
}
-#endif
size_t test_dsa()
{
size_t fails = 0;
-#if defined(BOTAN_HAS_DSA)
std::ifstream dsa_sig(PK_TEST_DATA_DIR "/dsa.vec");
fails += run_tests_bb(dsa_sig, "DSA Signature", "Signature", false,
@@ -61,8 +59,12 @@ size_t test_dsa()
{
return dsa_sig_kat(m["P"], m["Q"], m["G"], m["X"], m["Hash"], m["Msg"], m["Nonce"], m["Signature"]);
});
-#endif
return fails;
}
+#else
+
+SKIP_TEST(dsa);
+
+#endif // BOTAN_HAS_DSA
diff --git a/src/tests/test_ecc_pointmul.cpp b/src/tests/test_ecc_pointmul.cpp
new file mode 100644
index 000000000..220a3eecf
--- /dev/null
+++ b/src/tests/test_ecc_pointmul.cpp
@@ -0,0 +1,75 @@
+/*
+* (C) 2014,2015 Jack Lloyd
+*
+* Botan is released under the Simplified BSD License (see license.txt)
+*/
+
+#include "tests.h"
+
+#if defined(BOTAN_HAS_ECC_GROUP)
+
+#include "test_pubkey.h"
+
+#include <botan/pubkey.h>
+#include <botan/ecdsa.h>
+#include <botan/oids.h>
+#include <botan/hex.h>
+#include <iostream>
+#include <fstream>
+
+using namespace Botan;
+
+namespace {
+
+size_t ecc_point_mul(const std::string& group_id,
+ const std::string& m_s,
+ const std::string& X_s,
+ const std::string& Y_s)
+ {
+ EC_Group group(OIDS::lookup(group_id));
+
+ const BigInt m(m_s);
+ const BigInt X(X_s);
+ const BigInt Y(Y_s);
+
+ PointGFp p = group.get_base_point() * m;
+
+ size_t fails = 0;
+
+ if(p.get_affine_x() != X)
+ {
+ std::cout << p.get_affine_x() << " != " << X << std::endl;
+ ++fails;
+ }
+
+ if(p.get_affine_y() != Y)
+ {
+ std::cout << p.get_affine_y() << " != " << Y << std::endl;
+ ++fails;
+ }
+
+ return fails;
+ }
+
+}
+
+size_t test_ecc_pointmul()
+ {
+ size_t fails = 0;
+
+ std::ifstream ecc_mul(PK_TEST_DATA_DIR "/ecc.vec");
+
+ fails += run_tests_bb(ecc_mul, "ECC Point Mult", "Y", false,
+ [](std::map<std::string, std::string> m) -> size_t
+ {
+ return ecc_point_mul(m["Group"], m["m"], m["X"], m["Y"]);
+ });
+
+ return fails;
+ }
+
+#else
+
+SKIP_TEST(ecc_pointmul);
+
+#endif // BOTAN_HAS_ECC_GROUP
diff --git a/src/tests/test_ecdsa.cpp b/src/tests/test_ecdsa.cpp
index 53f32ab49..22a36f1a3 100644
--- a/src/tests/test_ecdsa.cpp
+++ b/src/tests/test_ecdsa.cpp
@@ -5,10 +5,11 @@
*/
#include "tests.h"
-#include "test_pubkey.h"
#if defined(BOTAN_HAS_ECDSA)
+#include "test_pubkey.h"
+
#include <botan/pubkey.h>
#include <botan/ecdsa.h>
#include <botan/oids.h>
@@ -41,62 +42,12 @@ size_t ecdsa_sig_kat(const std::string& group_id,
msg, rng, nonce, signature);
}
-size_t ecc_point_mul(const std::string& group_id,
- const std::string& m_s,
- const std::string& X_s,
- const std::string& Y_s)
- {
- EC_Group group(OIDS::lookup(group_id));
-
- const BigInt m(m_s);
- const BigInt X(X_s);
- const BigInt Y(Y_s);
-
- PointGFp p = group.get_base_point() * m;
-
- size_t fails = 0;
-
- if(p.get_affine_x() != X)
- {
- std::cout << p.get_affine_x() << " != " << X << std::endl;
- ++fails;
- }
-
- if(p.get_affine_y() != Y)
- {
- std::cout << p.get_affine_y() << " != " << Y << std::endl;
- ++fails;
- }
-
- return fails;
- }
-
}
-#endif
-
-size_t test_ecc_pointmul()
- {
- size_t fails = 0;
-
-#if defined(BOTAN_HAS_ECC_GROUP)
- std::ifstream ecc_mul(PK_TEST_DATA_DIR "/ecc.vec");
-
- fails += run_tests_bb(ecc_mul, "ECC Point Mult", "Y", false,
- [](std::map<std::string, std::string> m) -> size_t
- {
- return ecc_point_mul(m["Group"], m["m"], m["X"], m["Y"]);
- });
-#endif
-
- return fails;
- }
-
size_t test_ecdsa()
{
size_t fails = 0;
-#if defined(BOTAN_HAS_ECDSA)
std::ifstream ecdsa_sig(PK_TEST_DATA_DIR "/ecdsa.vec");
fails += run_tests_bb(ecdsa_sig, "ECDSA Signature", "Signature", false,
@@ -104,7 +55,12 @@ size_t test_ecdsa()
{
return ecdsa_sig_kat(m["Group"], m["X"], m["Hash"], m["Msg"], m["Nonce"], m["Signature"]);
});
-#endif
return fails;
}
+
+#else
+
+SKIP_TEST(ecdsa);
+
+#endif // BOTAN_HAS_ECDSA
diff --git a/src/tests/test_elg.cpp b/src/tests/test_elg.cpp
index cfe6375fb..da5047cd0 100644
--- a/src/tests/test_elg.cpp
+++ b/src/tests/test_elg.cpp
@@ -5,23 +5,20 @@
*/
#include "tests.h"
+
+#if defined(BOTAN_HAS_ELGAMAL)
+
#include "test_pubkey.h"
#include <botan/hex.h>
+#include <botan/elgamal.h>
+#include <botan/pubkey.h>
+#include <botan/dl_group.h>
#include <iostream>
#include <fstream>
-#if defined(BOTAN_HAS_ELGAMAL)
- #include <botan/elgamal.h>
-
- #include <botan/pubkey.h>
- #include <botan/dl_group.h>
-#endif
-
using namespace Botan;
-#if defined(BOTAN_HAS_ELGAMAL)
-
namespace {
size_t elgamal_kat(const std::string& p,
@@ -53,13 +50,11 @@ size_t elgamal_kat(const std::string& p,
}
}
-#endif
size_t test_elgamal()
{
size_t fails = 0;
-#if defined(BOTAN_HAS_ELGAMAL)
std::ifstream elgamal_enc(PK_TEST_DATA_DIR "/elgamal.vec");
fails += run_tests_bb(elgamal_enc, "ElGamal Encryption", "Ciphertext", true,
@@ -68,7 +63,12 @@ size_t test_elgamal()
return elgamal_kat(m["P"], m["G"], m["X"], m["Msg"],
m["Padding"], m["Nonce"], m["Ciphertext"]);
});
-#endif
return fails;
}
+
+#else
+
+SKIP_TEST(elgamal);
+
+#endif // BOTAN_HAS_ELGAMAL
diff --git a/src/tests/test_gost_3410.cpp b/src/tests/test_gost_3410.cpp
index 08dc1555b..3c83af805 100644
--- a/src/tests/test_gost_3410.cpp
+++ b/src/tests/test_gost_3410.cpp
@@ -5,10 +5,11 @@
*/
#include "tests.h"
-#include "test_pubkey.h"
#if defined(BOTAN_HAS_GOST_34_10_2001)
+#include "test_pubkey.h"
+
#include <botan/pubkey.h>
#include <botan/gost_3410.h>
#include <botan/oids.h>
@@ -42,13 +43,11 @@ size_t gost_verify(const std::string& group_id,
}
}
-#endif
size_t test_gost_3410()
{
size_t fails = 0;
-#if defined(BOTAN_HAS_GOST_34_10_2001)
std::ifstream ecdsa_sig(PK_TEST_DATA_DIR "/gost_3410.vec");
fails += run_tests_bb(ecdsa_sig, "GOST-34.10 Signature", "Signature", true,
@@ -56,8 +55,12 @@ size_t test_gost_3410()
{
return gost_verify(m["Group"], m["Pubkey"], m["Hash"], m["Msg"], m["Signature"]);
});
-#endif
return fails;
}
+#else
+
+SKIP_TEST(gost_3410);
+
+#endif // BOTAN_HAS_GOST_34_10_2001
diff --git a/src/tests/test_kdf.cpp b/src/tests/test_kdf.cpp
index 2ce8077ef..1e333381c 100644
--- a/src/tests/test_kdf.cpp
+++ b/src/tests/test_kdf.cpp
@@ -6,6 +6,8 @@
#include "tests.h"
+#if defined(BOTAN_HAS_KDF_BASE)
+
#include <botan/kdf.h>
#include <botan/lookup.h>
#include <botan/hex.h>
@@ -35,3 +37,9 @@ size_t test_kdf()
return run_tests_in_dir(TEST_DATA_DIR "kdf", test);
}
+
+#else
+
+SKIP_TEST(kdf);
+
+#endif // BOTAN_HAS_KDF_BASE
diff --git a/src/tests/test_mac.cpp b/src/tests/test_mac.cpp
index e191a6ed7..4d3833199 100644
--- a/src/tests/test_mac.cpp
+++ b/src/tests/test_mac.cpp
@@ -6,6 +6,8 @@
#include "tests.h"
+#if defined(BOTAN_HAS_MAC)
+
#include <botan/lookup.h>
#include <botan/mac.h>
#include <botan/hex.h>
@@ -93,3 +95,9 @@ size_t test_mac()
return run_tests_in_dir(TEST_DATA_DIR "mac", test);
}
+
+#else
+
+SKIP_TEST(mac);
+
+#endif // BOTAN_HAS_MAC
diff --git a/src/tests/test_mceliece.cpp b/src/tests/test_mceliece.cpp
index 8f1d3b6a3..c0ff1d435 100644
--- a/src/tests/test_mceliece.cpp
+++ b/src/tests/test_mceliece.cpp
@@ -8,6 +8,8 @@
#include "tests.h"
+#if defined(BOTAN_HAS_MCELIECE)
+
#include <botan/pubkey.h>
#include <botan/ecdsa.h>
#include <botan/rsa.h>
@@ -307,3 +309,9 @@ size_t test_mceliece()
test_report("McEliece", tests, fails);
return fails;
}
+
+#else
+
+SKIP_TEST(mceliece);
+
+#endif // BOTAN_HAS_MCELIECE
diff --git a/src/tests/test_modes.cpp b/src/tests/test_modes.cpp
index 35853ba82..2646c9059 100644
--- a/src/tests/test_modes.cpp
+++ b/src/tests/test_modes.cpp
@@ -6,6 +6,10 @@
#include "tests.h"
+#if defined(BOTAN_HAS_MODES)
+
+#if defined(BOTAN_HAS_FILTERS)
+
#include <botan/hex.h>
#include <botan/lookup.h>
#include <botan/cipher_mode.h>
@@ -96,3 +100,15 @@ size_t test_modes()
return run_tests_in_dir(TEST_DATA_DIR "modes", test);
}
+
+#else
+
+UNTESTED_WARNING(modes);
+
+#endif // BOTAN_HAS_FILTERS
+
+#else
+
+SKIP_TEST(modes);
+
+#endif // BOTAN_HAS_MODES
diff --git a/src/tests/test_nr.cpp b/src/tests/test_nr.cpp
index 25d84606c..1da12c8c8 100644
--- a/src/tests/test_nr.cpp
+++ b/src/tests/test_nr.cpp
@@ -5,22 +5,20 @@
*/
#include "tests.h"
-#include "test_pubkey.h"
#if defined(BOTAN_HAS_NYBERG_RUEPPEL)
- #include <botan/nr.h>
- #include <botan/pubkey.h>
- #include <botan/dl_group.h>
-#endif
+
+#include "test_pubkey.h"
#include <botan/hex.h>
+#include <botan/nr.h>
+#include <botan/pubkey.h>
+#include <botan/dl_group.h>
#include <iostream>
#include <fstream>
using namespace Botan;
-#if defined(BOTAN_HAS_NYBERG_RUEPPEL)
-
namespace {
size_t nr_sig_kat(const std::string& p,
@@ -51,13 +49,11 @@ size_t nr_sig_kat(const std::string& p,
}
}
-#endif
size_t test_nr()
{
size_t fails = 0;
-#if defined(BOTAN_HAS_NYBERG_RUEPPEL)
std::ifstream nr_sig(PK_TEST_DATA_DIR "/nr.vec");
fails += run_tests_bb(nr_sig, "NR Signature", "Signature", true,
@@ -65,8 +61,12 @@ size_t test_nr()
{
return nr_sig_kat(m["P"], m["Q"], m["G"], m["X"], m["Hash"], m["Msg"], m["Nonce"], m["Signature"]);
});
-#endif
return fails;
}
+#else
+
+SKIP_TEST(nr);
+
+#endif // BOTAN_HAS_NYBERG_RUEPPEL
diff --git a/src/tests/test_ocb.cpp b/src/tests/test_ocb.cpp
index 513b34dc2..4069625b5 100644
--- a/src/tests/test_ocb.cpp
+++ b/src/tests/test_ocb.cpp
@@ -5,9 +5,12 @@
*/
#include "tests.h"
-#include <iostream>
#if defined(BOTAN_HAS_AEAD_OCB)
+
+#if defined(BOTAN_HAS_AES)
+
+#include <iostream>
#include <botan/ocb.h>
#include <botan/hex.h>
#include <botan/sha2_32.h>
@@ -102,14 +105,11 @@ size_t test_ocb_long(size_t keylen, size_t taglen,
}
}
-#endif
size_t test_ocb()
{
size_t fails = 0;
-#if defined(BOTAN_HAS_AEAD_OCB)
-
fails += test_ocb_long(128, 128, "67E944D23256C5E0B6C61FA22FDF1EA2");
fails += test_ocb_long(192, 128, "F673F2C3E7174AAE7BAE986CA9F29E17");
fails += test_ocb_long(256, 128, "D90EB8E9C977C88B79DD793D7FFA161C");
@@ -120,7 +120,18 @@ size_t test_ocb()
fails += test_ocb_long(192, 64, "0066BC6E0EF34E24");
fails += test_ocb_long(256, 64, "7D4EA5D445501CBE");
test_report("OCB long", 9, fails);
-#endif
return fails;
}
+
+#else
+
+UNTESTED_WARNING(ocb);
+
+#endif // BOTAN_HAS_AES
+
+#else
+
+SKIP_TEST(ocb);
+
+#endif // BOTAN_HAS_AEAD_OCB
diff --git a/src/tests/test_pbkdf.cpp b/src/tests/test_pbkdf.cpp
index 703a7bc80..c60cf9d78 100644
--- a/src/tests/test_pbkdf.cpp
+++ b/src/tests/test_pbkdf.cpp
@@ -6,6 +6,8 @@
#include "tests.h"
+#if defined(BOTAN_HAS_PBKDF)
+
#include <botan/pbkdf.h>
#include <botan/lookup.h>
#include <botan/hex.h>
@@ -37,3 +39,9 @@ size_t test_pbkdf()
return run_tests_in_dir(TEST_DATA_DIR "pbkdf", test);
}
+
+#else
+
+SKIP_TEST(pbkdf);
+
+#endif // BOTAN_HAS_PBKDF
diff --git a/src/tests/test_pubkey.cpp b/src/tests/test_pubkey.cpp
index 00ece8559..c3f2017f6 100644
--- a/src/tests/test_pubkey.cpp
+++ b/src/tests/test_pubkey.cpp
@@ -5,6 +5,9 @@
*/
#include "tests.h"
+
+#if defined(BOTAN_HAS_PUBLIC_KEY_CRYPTO)
+
#include "test_rng.h"
#include "test_pubkey.h"
@@ -16,13 +19,9 @@
#include <memory>
#include <botan/oids.h>
-
-#if defined(BOTAN_HAS_PUBLIC_KEY_CRYPTO)
- #include <botan/x509_key.h>
- #include <botan/pkcs8.h>
- #include <botan/pubkey.h>
-
-#endif
+#include <botan/x509_key.h>
+#include <botan/pkcs8.h>
+#include <botan/pubkey.h>
#if defined(BOTAN_HAS_RSA)
#include <botan/rsa.h>
@@ -401,3 +400,9 @@ size_t test_pk_keygen()
return fails;
}
+
+#else
+
+SKIP_TEST(pk_keygen);
+
+#endif // BOTAN_HAS_PUBLIC_KEY_CRYPTO
diff --git a/src/tests/test_rsa.cpp b/src/tests/test_rsa.cpp
index 4133d13c0..06944ac56 100644
--- a/src/tests/test_rsa.cpp
+++ b/src/tests/test_rsa.cpp
@@ -5,6 +5,9 @@
*/
#include "tests.h"
+
+#if defined(BOTAN_HAS_RSA)
+
#include "test_pubkey.h"
#include <botan/pubkey.h>
@@ -118,3 +121,8 @@ size_t test_rsa()
return fails;
}
+#else
+
+SKIP_TEST(rsa);
+
+#endif // BOTAN_HAS_RSA
diff --git a/src/tests/test_rw.cpp b/src/tests/test_rw.cpp
index f5a4f8cdb..431b070b2 100644
--- a/src/tests/test_rw.cpp
+++ b/src/tests/test_rw.cpp
@@ -5,21 +5,19 @@
*/
#include "tests.h"
+
+#if defined(BOTAN_HAS_RW)
+
#include "test_pubkey.h"
#include <botan/hex.h>
#include <iostream>
#include <fstream>
-
-#if defined(BOTAN_HAS_RW)
-
- #include <botan/pubkey.h>
- #include <botan/rw.h>
-#endif
+#include <botan/pubkey.h>
+#include <botan/rw.h>
using namespace Botan;
-#if defined(BOTAN_HAS_RW)
namespace {
const std::string padding = "EMSA2(SHA-1)";
@@ -60,13 +58,11 @@ size_t rw_sig_verify(const std::string& e,
}
}
-#endif
size_t test_rw()
{
size_t fails = 0;
-#if defined(BOTAN_HAS_RW)
std::ifstream rw_sig(PK_TEST_DATA_DIR "/rw_sig.vec");
std::ifstream rw_verify(PK_TEST_DATA_DIR "/rw_verify.vec");
@@ -81,8 +77,12 @@ size_t test_rw()
{
return rw_sig_verify(m["E"], m["N"], m["Msg"], m["Signature"]);
});
-#endif
return fails;
}
+#else
+
+SKIP_TEST(rw);
+
+#endif // BOTAN_HAS_RW
diff --git a/src/tests/test_srp6.cpp b/src/tests/test_srp6.cpp
index fcc049c11..dd05d02a5 100644
--- a/src/tests/test_srp6.cpp
+++ b/src/tests/test_srp6.cpp
@@ -1,4 +1,7 @@
#include "tests.h"
+
+#if defined(BOTAN_HAS_SRP6)
+
#include <botan/srp6.h>
#include <iostream>
@@ -37,3 +40,9 @@ size_t test_srp6()
return fails;
}
+
+#else
+
+SKIP_TEST(srp6);
+
+#endif // BOTAN_HAS_SRP6
diff --git a/src/tests/test_stream.cpp b/src/tests/test_stream.cpp
index 0e9f67c9f..4828d44fd 100644
--- a/src/tests/test_stream.cpp
+++ b/src/tests/test_stream.cpp
@@ -6,6 +6,8 @@
#include "tests.h"
+#if defined(BOTAN_HAS_STREAM_CIPHER)
+
#include <botan/stream_cipher.h>
#include <botan/lookup.h>
#include <botan/hex.h>
@@ -83,3 +85,9 @@ size_t test_stream()
return run_tests_in_dir(TEST_DATA_DIR "/stream", test);
}
+
+#else
+
+SKIP_TEST(stream);
+
+#endif // BOTAN_HAS_STREAM_CIPHER
diff --git a/src/tests/test_tss.cpp b/src/tests/test_tss.cpp
index 23ea89b19..561336f9d 100644
--- a/src/tests/test_tss.cpp
+++ b/src/tests/test_tss.cpp
@@ -6,11 +6,10 @@
#include "tests.h"
-#include <botan/hex.h>
-#include <iostream>
-
#if defined(BOTAN_HAS_THRESHOLD_SECRET_SHARING)
+#include <iostream>
+#include <botan/hex.h>
#include <botan/tss.h>
size_t test_tss()
@@ -53,9 +52,7 @@ size_t test_tss()
return fails;
}
#else
-size_t test_tss()
- {
- std::cout << "Skipping TSS tests" << std::endl;
- return 1;
- }
-#endif
+
+SKIP_TEST(tss);
+
+#endif // BOTAN_HAS_THRESHOLD_SECRET_SHARING
diff --git a/src/tests/tests.h b/src/tests/tests.h
index a086281e7..15ce4b4ab 100644
--- a/src/tests/tests.h
+++ b/src/tests/tests.h
@@ -1,5 +1,6 @@
/*
* (C) 2014,2015 Jack Lloyd
+* (C) 2015 Simon Warta (Kullo GmbH)
*
* Botan is released under the Simplified BSD License (see license.txt)
*/
@@ -7,12 +8,14 @@
#ifndef BOTAN_TESTS_H__
#define BOTAN_TESTS_H__
+#include <botan/build.h>
#include <botan/rng.h>
#include <functional>
#include <istream>
#include <map>
#include <string>
#include <vector>
+#include <iostream>
Botan::RandomNumberGenerator& test_rng();
@@ -102,4 +105,31 @@ size_t test_nist_x509();
size_t test_srp6();
size_t test_compression();
+#define SKIP_TEST(testname) \
+ size_t test_ ## testname() { \
+ std::cout << "Skipping tests: " << # testname << std::endl; \
+ return 0; \
+ } \
+
+/*
+ * Warn if a test requires loading more modules than necessary to build
+ * the lib. E.g.
+ * $ ./configure.py --no-autoload --enable-modules='ocb'
+ * $ make
+ * $ ./botan-test ocb
+ * warns the user whereas
+ * $ ./configure.py --no-autoload --enable-modules='ocb,aes'
+ * $ make
+ * $ ./botan-test ocb
+ * runs the test.
+ */
+#define UNTESTED_WARNING(testname) \
+ size_t test_ ## testname() { \
+ std::cout << "Skipping tests: " << # testname << std::endl; \
+ std::cout << "WARNING: " << # testname << " has been compiled " \
+ << "but is not tested due to other missing modules." \
+ << std::endl; \
+ return 0; \
+ } \
+
#endif
diff --git a/src/tests/unit_ecc.cpp b/src/tests/unit_ecc.cpp
index 4c35caa48..8498e3b43 100644
--- a/src/tests/unit_ecc.cpp
+++ b/src/tests/unit_ecc.cpp
@@ -6,13 +6,12 @@
#include "tests.h"
-#include <botan/hex.h>
-#include <iostream>
-#include <memory>
-
#if defined(BOTAN_HAS_ECC_GROUP)
+#include <iostream>
+#include <memory>
#include <botan/bigint.h>
+#include <botan/hex.h>
#include <botan/numthry.h>
#include <botan/curve_gfp.h>
#include <botan/point_gfp.h>
@@ -901,7 +900,6 @@ size_t ecc_randomized_test()
test_report("ECC Randomized", tests, fails);
return fails;
}
-#endif
}
@@ -909,7 +907,6 @@ size_t test_ecc_unit()
{
size_t fails = 0;
-#if defined(BOTAN_HAS_ECC_GROUP)
fails += test_point_turn_on_sp_red_mul();
fails += test_coordinates();
fails += test_point_transformation ();
@@ -938,7 +935,12 @@ size_t test_ecc_unit()
test_report("ECC", 0, fails);
ecc_randomized_test();
-#endif
return fails;
}
+
+#else
+
+SKIP_TEST(ecc_unit);
+
+#endif // BOTAN_HAS_ECC_GROUP
diff --git a/src/tests/unit_ecdsa.cpp b/src/tests/unit_ecdsa.cpp
index 432fc22bd..53d12aeb7 100644
--- a/src/tests/unit_ecdsa.cpp
+++ b/src/tests/unit_ecdsa.cpp
@@ -11,15 +11,18 @@
#include "tests.h"
#if defined(BOTAN_HAS_ECDSA)
-#include <botan/hex.h>
+#if defined(BOTAN_HAS_RSA)
+
+#include <botan/hex.h>
#include <botan/pubkey.h>
#include <botan/ecdsa.h>
#include <botan/rsa.h>
+#include <botan/oids.h>
+
#if defined(BOTAN_HAS_X509_CERTIFICATES)
#include <botan/x509cert.h>
#endif
-#include <botan/oids.h>
#include <iostream>
#include <fstream>
@@ -493,6 +496,12 @@ size_t test_ecdsa_unit()
#else
-size_t test_ecdsa_unit() { return 0; }
+UNTESTED_WARNING(ecdsa_unit);
-#endif
+#endif // BOTAN_HAS_RSA
+
+#else
+
+SKIP_TEST(ecdsa_unit);
+
+#endif // BOTAN_HAS_ECDSA
diff --git a/src/tests/unit_x509.cpp b/src/tests/unit_x509.cpp
index 2388dc920..8776305e3 100644
--- a/src/tests/unit_x509.cpp
+++ b/src/tests/unit_x509.cpp
@@ -6,7 +6,15 @@
#include "tests.h"
+#if defined(BOTAN_HAS_X509_CERTIFICATES)
+
+#if defined(BOTAN_HAS_RSA) && defined(BOTAN_HAS_DSA)
+
#include <botan/filters.h>
+#include <botan/x509self.h>
+#include <botan/x509path.h>
+#include <botan/x509_ca.h>
+#include <botan/pkcs10.h>
#if defined(BOTAN_HAS_RSA)
@@ -21,23 +29,11 @@
#include <botan/ecdsa.h>
#endif
-#if defined(BOTAN_HAS_X509_CERTIFICATES)
- #include <botan/x509self.h>
- #include <botan/x509path.h>
- #include <botan/x509_ca.h>
- #include <botan/pkcs10.h>
-#endif
-
using namespace Botan;
#include <iostream>
#include <memory>
-
-#if defined(BOTAN_HAS_X509_CERTIFICATES) && \
- defined(BOTAN_HAS_RSA) && \
- defined(BOTAN_HAS_DSA)
-
namespace {
u64bit key_id(const Public_Key* key)
@@ -251,7 +247,12 @@ size_t test_x509()
#else
-size_t test_x509() { return 0; }
+UNTESTED_WARNING(x509);
-#endif
+#endif // BOTAN_HAS_RSA && BOTAN_HAS_DSA
+
+#else
+
+SKIP_TEST(x509);
+#endif // BOTAN_HAS_X509_CERTIFICATES