4 /***** private prototypes *****/
5 static int key_compare_function( void const *new_value, void const *value_in_tree );
11 /****************************************************************************/
12 void test_lfds700_btree_au_fail_and_overwrite_on_existing_key()
14 enum lfds700_btree_au_insert_result
17 enum lfds700_misc_validity
18 dvs = LFDS700_MISC_VALIDITY_VALID;
20 struct lfds700_btree_au_element
25 struct lfds700_btree_au_state
28 struct lfds700_misc_prng_state
34 /* TRD : the random_adds tests with fail and overwrite don't (can't, not in a performant manner)
35 test that the fail and/or overwrite of user data has *actually* happened - they use the
36 return value from the link function call, rather than empirically observing the final
39 as such, we now have a couple of single threaded tests where we check that the user data
40 value really is being modified (or not modified, as the case may be)
43 internal_display_test_name( "Fail and overwrite on existing key" );
45 lfds700_misc_prng_init( &ps );
47 /* TRD : so, we make a tree which is fail on existing
48 add one element, with a known user data
49 we then try to add the same key again, with a different user data
50 the call should fail, and then we get the element by its key
51 and check its user data is unchanged
52 (and confirm the failed link returned the correct existing_baue)
53 that's the first test done
56 lfds700_btree_au_init_valid_on_current_logical_core( &baus, key_compare_function, LFDS700_BTREE_AU_EXISTING_KEY_FAIL, NULL );
58 LFDS700_BTREE_AU_SET_KEY_IN_ELEMENT( baue_one, 0 );
59 LFDS700_BTREE_AU_SET_VALUE_IN_ELEMENT( baue_one, 1 );
60 alr = lfds700_btree_au_insert( &baus, &baue_one, NULL, &ps );
62 if( alr != LFDS700_BTREE_AU_INSERT_RESULT_SUCCESS )
63 dvs = LFDS700_MISC_VALIDITY_INVALID_TEST_DATA;
65 LFDS700_BTREE_AU_SET_KEY_IN_ELEMENT( baue_two, 0 );
66 LFDS700_BTREE_AU_SET_VALUE_IN_ELEMENT( baue_two, 2 );
67 alr = lfds700_btree_au_insert( &baus, &baue_two, &existing_baue, &ps );
69 if( alr != LFDS700_BTREE_AU_INSERT_RESULT_FAILURE_EXISTING_KEY )
70 dvs = LFDS700_MISC_VALIDITY_INVALID_TEST_DATA;
72 if( existing_baue != &baue_one )
73 dvs = LFDS700_MISC_VALIDITY_INVALID_TEST_DATA;
75 value = LFDS700_BTREE_AU_GET_VALUE_FROM_ELEMENT( *existing_baue );
77 if( (void *) (lfds700_pal_uint_t) value != (void *) (lfds700_pal_uint_t) 1 )
78 dvs = LFDS700_MISC_VALIDITY_INVALID_TEST_DATA;
80 lfds700_btree_au_cleanup( &baus, NULL );
82 /* TRD : second test, make a tree which is overwrite on existing
83 add one element, with a known user data
84 we then try to add the same key again, with a different user data
85 the call should succeed, and then we get the element by its key
86 and check its user data is changed
87 (and confirm the failed link returned the correct existing_baue)
88 that's the secondtest done
91 lfds700_btree_au_init_valid_on_current_logical_core( &baus, key_compare_function, LFDS700_BTREE_AU_EXISTING_KEY_OVERWRITE, NULL );
93 LFDS700_BTREE_AU_SET_KEY_IN_ELEMENT( baue_one, 0 );
94 LFDS700_BTREE_AU_SET_VALUE_IN_ELEMENT( baue_one, 1 );
95 alr = lfds700_btree_au_insert( &baus, &baue_one, NULL, &ps );
97 if( alr != LFDS700_BTREE_AU_INSERT_RESULT_SUCCESS )
98 dvs = LFDS700_MISC_VALIDITY_INVALID_TEST_DATA;
100 LFDS700_BTREE_AU_SET_KEY_IN_ELEMENT( baue_two, 0 );
101 LFDS700_BTREE_AU_SET_VALUE_IN_ELEMENT( baue_two, 2 );
102 alr = lfds700_btree_au_insert( &baus, &baue_two, NULL, &ps );
104 if( alr != LFDS700_BTREE_AU_INSERT_RESULT_SUCCESS_OVERWRITE )
105 dvs = LFDS700_MISC_VALIDITY_INVALID_TEST_DATA;
107 lfds700_btree_au_cleanup( &baus, NULL );
109 // TRD : print the test result
110 internal_display_test_result( 1, "btree_au", dvs );
119 /****************************************************************************/
120 #pragma warning( disable : 4100 )
122 static int key_compare_function( void const *new_key, void const *key_in_tree )
127 // TRD : key_new can be any value in its range
128 // TRD : key_in_tree can be any value in its range
130 if( (lfds700_pal_uint_t) new_key < (lfds700_pal_uint_t) key_in_tree )
133 if( (lfds700_pal_uint_t) new_key > (lfds700_pal_uint_t) key_in_tree )
139 #pragma warning( default : 4100 )