From 5a48ac0c6e3c2cc98c5088323943a440ac774f49 Mon Sep 17 00:00:00 2001 From: Dmitry-Me Date: Fri, 22 Nov 2019 18:11:38 +0300 Subject: [PATCH] Improve test coverage for invalid use of bool parameters --- test/testfunctions.cpp | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/test/testfunctions.cpp b/test/testfunctions.cpp index 70c2f7621..b69d6990c 100644 --- a/test/testfunctions.cpp +++ b/test/testfunctions.cpp @@ -432,8 +432,16 @@ private: "}"); ASSERT_EQUALS("[test.cpp:2]: (error) Invalid memset() argument nr 3. A non-boolean value is required.\n", errout.str()); - check("int f() { strtol(a,b,sizeof(a)!=12); }"); - ASSERT_EQUALS("[test.cpp:1]: (error) Invalid strtol() argument nr 3. The value is 0 or 1 (boolean) but the valid values are '0,2:36'.\n", errout.str()); + check("void boolArgZeroIsInvalidButOneIsValid(int param) {\n" + " void* buffer = calloc(param > 0, 10);\n" + " free(buffer);\n" + "}"); + ASSERT_EQUALS("[test.cpp:2]: (error) Invalid calloc() argument nr 1. The value is 0 or 1 (boolean) but the valid values are '1:'.\n", errout.str()); + + check("void boolArgZeroIsValidButOneIsInvalid(int param) {\n" + " strtol(a, b, param > 0);\n" + "}"); + ASSERT_EQUALS("[test.cpp:2]: (error) Invalid strtol() argument nr 3. The value is 0 or 1 (boolean) but the valid values are '0,2:36'.\n", errout.str()); check("int f() { strtol(a,b,1); }"); ASSERT_EQUALS("[test.cpp:1]: (error) Invalid strtol() argument nr 3. The value is 1 but the valid values are '0,2:36'.\n", errout.str());