Il giorno sab, 01/10/2011 alle 19.39 +0200, Aleksander Morgado ha scritto: > Hi hi, > > > here are some unit tests for hash helpers (pdf-hash-add-bool, > > pdf-hash-add-i32 and pdf-hash-addu32). > > > > Some minor things: > > +/* Copyright (C) 2008-2011 Free Software Foundation, Inc. */ > New files should have listed only the current year in the copyright > line. > > +#include <check.h> > +#include <pdf-test-common.h> > +/* > + * Test: pdf_hash_add_bool_001 > Please add an empty line between the last include and the beginning of > the test description. > > And regarding the tests themselves: > * For booleans, include tests adding TRUE and FALSE. > * For u32s, include tests not only for the MAX u32, but also for the > minimum one (0), just for completeness. > * For i32s, include tests not only for the MAX i32, but also for the > MIN i32. > > Cheers! >
Hi! Here's the new patch with your comments addressed
=== modified file 'torture/unit/Makefile.am' --- torture/unit/Makefile.am 2011-08-29 15:17:29 +0000 +++ torture/unit/Makefile.am 2011-09-23 12:55:51 +0000 @@ -87,6 +87,9 @@ base/hash/pdf-hash-add-list.c \ base/hash/pdf-hash-add-stm.c \ base/hash/pdf-hash-add-text.c \ + base/hash/pdf-hash-add-bool.c \ + base/hash/pdf-hash-add-i32.c \ + base/hash/pdf-hash-add-u32.c \ base/hash/pdf-hash-size.c \ base/hash/pdf-hash-get-value.c \ base/hash/pdf-hash-key-p.c \ === added file 'torture/unit/base/hash/pdf-hash-add-bool.c' --- torture/unit/base/hash/pdf-hash-add-bool.c 1970-01-01 00:00:00 +0000 +++ torture/unit/base/hash/pdf-hash-add-bool.c 2011-10-01 19:54:11 +0000 @@ -0,0 +1,102 @@ +/* -*- mode: C -*- + * + * File: pdf-hash-add-bool.c + * Date: Mon Sep 19 12:43:00 2011 + * + * GNU PDF Library - Unit tests for pdf_hash_add_bool + * + */ + +/* Copyright (C) 2011 Free Software Foundation, Inc. */ + +/* This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +#include <config.h> + +#include <stdbool.h> +#include <stdio.h> +#include <pdf.h> +#include <check.h> +#include <pdf-test-common.h> + +/* + * Test: pdf_hash_add_bool_001 + * Description: + * Try to add a bool variable (PDF_TRUE) inside a hash table. + * Success condition: + * Returns PDF_TRUE + */ +START_TEST (pdf_hash_add_bool_001) +{ + pdf_hash_t *table; + pdf_bool_t inner = PDF_TRUE; + pdf_error_t *error = NULL; + + + table = pdf_hash_new (NULL); + + fail_if (pdf_hash_add_bool (table, + "theKey", + inner, + &error) != PDF_TRUE); + fail_if (error != NULL); + + pdf_hash_destroy (table); +} +END_TEST + +/* + * Test: pdf_hash_add_bool_002 + * Description: + * Try to add a bool variable (PDF_FALSE) inside a hash table. + * Success condition: + * Returns PDF_TRUE + */ +START_TEST (pdf_hash_add_bool_002) +{ + pdf_hash_t *table; + pdf_bool_t inner = PDF_FALSE; + pdf_error_t *error = NULL; + + + table = pdf_hash_new (NULL); + + fail_if (pdf_hash_add_bool (table, + "theKey", + inner, + &error) != PDF_TRUE); + fail_if (error != NULL); + + pdf_hash_destroy (table); +} +END_TEST + +/* + * Test case creation function + */ +TCase * +test_pdf_hash_add_bool (void) +{ + TCase *tc = tcase_create ("pdf_hash_add_bool"); + + tcase_add_test (tc, pdf_hash_add_bool_001); + tcase_add_test (tc, pdf_hash_add_bool_002); + tcase_add_checked_fixture (tc, + pdf_test_setup, + pdf_test_teardown); + return tc; +} + +/* End of pdf-hash-add-bool.c */ === added file 'torture/unit/base/hash/pdf-hash-add-i32.c' --- torture/unit/base/hash/pdf-hash-add-i32.c 1970-01-01 00:00:00 +0000 +++ torture/unit/base/hash/pdf-hash-add-i32.c 2011-10-01 19:56:37 +0000 @@ -0,0 +1,102 @@ +/* -*- mode: C -*- + * + * File: pdf-hash-add-i32.c + * Date: Mon Sep 19 12:43:00 2011 + * + * GNU PDF Library - Unit tests for pdf_hash_add_i32 + * + */ + +/* Copyright (C) 2011 Free Software Foundation, Inc. */ + +/* This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +#include <config.h> + +#include <stdbool.h> +#include <stdio.h> +#include <pdf.h> +#include <check.h> +#include <pdf-test-common.h> + +/* + * Test: pdf_hash_add_i32_001 + * Description: + * Try to add a i32 (INT32_MAX) variable inside a hash table. + * Success condition: + * Returns PDF_TRUE + */ +START_TEST (pdf_hash_add_i32_001) +{ + pdf_hash_t *table; + pdf_i32_t inner = INT32_MAX; + pdf_error_t *error = NULL; + + + table = pdf_hash_new (NULL); + + fail_if (pdf_hash_add_i32 (table, + "theKey", + inner, + &error) != PDF_TRUE); + fail_if (error != NULL); + + pdf_hash_destroy (table); +} +END_TEST + +/* + * Test: pdf_hash_add_i32_002 + * Description: + * Try to add a i32 (INT32_MIN) variable inside a hash table. + * Success condition: + * Returns PDF_TRUE + */ +START_TEST (pdf_hash_add_i32_002) +{ + pdf_hash_t *table; + pdf_i32_t inner = INT32_MIN; + pdf_error_t *error = NULL; + + + table = pdf_hash_new (NULL); + + fail_if (pdf_hash_add_i32 (table, + "theKey", + inner, + &error) != PDF_TRUE); + fail_if (error != NULL); + + pdf_hash_destroy (table); +} +END_TEST + +/* + * Test case creation function + */ +TCase * +test_pdf_hash_add_i32 (void) +{ + TCase *tc = tcase_create ("pdf_hash_add_i32"); + + tcase_add_test (tc, pdf_hash_add_i32_001); + tcase_add_test (tc, pdf_hash_add_i32_002); + tcase_add_checked_fixture (tc, + pdf_test_setup, + pdf_test_teardown); + return tc; +} + +/* End of pdf-hash-add-i32.c */ === added file 'torture/unit/base/hash/pdf-hash-add-u32.c' --- torture/unit/base/hash/pdf-hash-add-u32.c 1970-01-01 00:00:00 +0000 +++ torture/unit/base/hash/pdf-hash-add-u32.c 2011-10-01 19:58:46 +0000 @@ -0,0 +1,102 @@ +/* -*- mode: C -*- + * + * File: pdf-hash-add-u32.c + * Date: Mon Sep 19 12:43:00 2011 + * + * GNU PDF Library - Unit tests for pdf_hash_add_u32 + * + */ + +/* Copyright (C) 2011 Free Software Foundation, Inc. */ + +/* This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +#include <config.h> + +#include <stdbool.h> +#include <stdio.h> +#include <pdf.h> +#include <check.h> +#include <pdf-test-common.h> + +/* + * Test: pdf_hash_add_u32_001 + * Description: + * Try to add a u32 variable (UINT32_MAX) inside a hash table. + * Success condition: + * Returns PDF_TRUE + */ +START_TEST (pdf_hash_add_u32_001) +{ + pdf_hash_t *table; + pdf_u32_t inner = UINT32_MAX; + pdf_error_t *error = NULL; + + + table = pdf_hash_new (NULL); + + fail_if (pdf_hash_add_u32 (table, + "theKey", + inner, + &error) != PDF_TRUE); + fail_if (error != NULL); + + pdf_hash_destroy (table); +} +END_TEST + +/* + * Test: pdf_hash_add_u32_002 + * Description: + * Try to add a u32 variable (0) inside a hash table. + * Success condition: + * Returns PDF_TRUE + */ +START_TEST (pdf_hash_add_u32_002) +{ + pdf_hash_t *table; + pdf_u32_t inner = 0; + pdf_error_t *error = NULL; + + + table = pdf_hash_new (NULL); + + fail_if (pdf_hash_add_u32 (table, + "theKey", + inner, + &error) != PDF_TRUE); + fail_if (error != NULL); + + pdf_hash_destroy (table); +} +END_TEST + +/* + * Test case creation function + */ +TCase * +test_pdf_hash_add_u32 (void) +{ + TCase *tc = tcase_create ("pdf_hash_add_u32"); + + tcase_add_test (tc, pdf_hash_add_u32_001); + tcase_add_test (tc, pdf_hash_add_u32_002); + tcase_add_checked_fixture (tc, + pdf_test_setup, + pdf_test_teardown); + return tc; +} + +/* End of pdf-hash-add-u32.c */ === modified file 'torture/unit/base/hash/tsuite-hash.c' --- torture/unit/base/hash/tsuite-hash.c 2011-02-24 22:52:23 +0000 +++ torture/unit/base/hash/tsuite-hash.c 2011-09-23 12:55:27 +0000 @@ -36,6 +36,9 @@ extern TCase *test_pdf_hash_add_time (void); extern TCase *test_pdf_hash_add_hash (void); extern TCase *test_pdf_hash_add_text (void); +extern TCase *test_pdf_hash_add_bool (void); +extern TCase *test_pdf_hash_add_i32 (void); +extern TCase *test_pdf_hash_add_u32 (void); extern TCase *test_pdf_hash_add_list (void); extern TCase *test_pdf_hash_add_stm (void); extern TCase *test_pdf_hash_remove (void); @@ -63,6 +66,9 @@ suite_add_tcase (s, test_pdf_hash_add_time ()); suite_add_tcase (s, test_pdf_hash_add_hash ()); suite_add_tcase (s, test_pdf_hash_add_text ()); + suite_add_tcase (s, test_pdf_hash_add_bool ()); + suite_add_tcase (s, test_pdf_hash_add_i32 ()); + suite_add_tcase (s, test_pdf_hash_add_u32 ()); suite_add_tcase (s, test_pdf_hash_add_list ()); suite_add_tcase (s, test_pdf_hash_add_stm ());