| 1 |
/* File: layout_visible_set_test.c; Copyright and License: see below */ |
| 2 |
|
| 3 |
#include "layout_visible_set_test.h" |
| 4 |
#include "layout/layout_visible_set.h" |
| 5 |
#include "set/data_visible_set.h" |
| 6 |
#include "test_fixture.h" |
| 7 |
#include "test_expect.h" |
| 8 |
#include "test_environment_assert.h" |
| 9 |
#include "test_case_result.h" |
| 10 |
|
| 11 |
static test_fixture_t * set_up(); |
| 12 |
static void tear_down( test_fixture_t *fix ); |
| 13 |
static test_case_result_t test_empty_model( test_fixture_t *fix ); |
| 14 |
static test_case_result_t test_normal_model( test_fixture_t *fix ); |
| 15 |
static test_case_result_t test_too_big_model( test_fixture_t *fix ); |
| 16 |
static test_case_result_t test_inconsistent_model( test_fixture_t *fix ); |
| 17 |
static data_visible_set_t* init_empty_input_data(); |
| 18 |
static data_visible_set_t* init_fake_input_data( uint_fast32_t classifiers, uint_fast32_t features, uint_fast32_t relationships ); |
| 19 |
|
| 20 |
test_suite_t layout_visible_set_test_get_suite(void) |
| 21 |
{ |
| 22 |
test_suite_t result; |
| 23 |
test_suite_init( &result, |
| 24 |
"layout_visible_set_test_get_suite", |
| 25 |
TEST_CATEGORY_UNIT | TEST_CATEGORY_CONTINUOUS | TEST_CATEGORY_COVERAGE, |
| 26 |
&set_up, |
| 27 |
&tear_down |
| 28 |
); |
| 29 |
test_suite_add_test_case( &result, "test_empty_model", &test_empty_model ); |
| 30 |
test_suite_add_test_case( &result, "test_normal_model", &test_normal_model ); |
| 31 |
test_suite_add_test_case( &result, "test_too_big_model", &test_too_big_model ); |
| 32 |
test_suite_add_test_case( &result, "test_inconsistent_model", &test_inconsistent_model ); |
| 33 |
return result; |
| 34 |
} |
| 35 |
|
| 36 |
static test_fixture_t * set_up() |
| 37 |
{ |
| 38 |
return NULL; |
| 39 |
} |
| 40 |
|
| 41 |
static void tear_down( test_fixture_t *fix ) |
| 42 |
{ |
| 43 |
} |
| 44 |
|
| 45 |
static data_visible_set_t* init_empty_input_data() |
| 46 |
{ |
| 47 |
static data_visible_set_t empty_input_data; |
| 48 |
data_visible_set_init( &empty_input_data ); |
| 49 |
data_visible_set_update_containment_cache ( &empty_input_data ); |
| 50 |
TEST_ENVIRONMENT_ASSERT ( ! data_visible_set_is_valid ( &empty_input_data ) ); |
| 51 |
return &empty_input_data; |
| 52 |
return TEST_CASE_RESULT_OK; |
| 53 |
} |
| 54 |
|
| 55 |
static data_visible_set_t* init_fake_input_data( uint_fast32_t classifiers, uint_fast32_t features, uint_fast32_t relationships ) |
| 56 |
{ |
| 57 |
u8_error_t data_err; |
| 58 |
static data_visible_set_t fake_input_data; |
| 59 |
|
| 60 |
data_visible_set_init( &fake_input_data ); |
| 61 |
|
| 62 |
/* initialize the fake_input_data.diagram */ |
| 63 |
{ |
| 64 |
|
| 65 |
data_err = data_diagram_init( &(fake_input_data.diagram), |
| 66 |
3, /* diagram_id */ |
| 67 |
DATA_ROW_VOID, /* parent_diagram_id */ |
| 68 |
DATA_DIAGRAM_TYPE_UML_CLASS_DIAGRAM, /* diagram_type */ |
| 69 |
"stereo_t", /* stereotype */ |
| 70 |
"diagram_name", |
| 71 |
"diagram_description", |
| 72 |
32000, /* list_order */ |
| 73 |
DATA_DIAGRAM_FLAG_NONE, |
| 74 |
"bfe86725-1507-4789-ac92-82f1090a1984" |
| 75 |
); |
| 76 |
TEST_ENVIRONMENT_ASSERT( data_err == U8_ERROR_NONE ); |
| 77 |
} |
| 78 |
|
| 79 |
/* initialize the fake_input_data.visible_classifiers */ |
| 80 |
fake_input_data.visible_classifier_count = classifiers; |
| 81 |
for ( uint_fast32_t c_idx = 0; c_idx < classifiers; c_idx ++ ) |
| 82 |
{ |
| 83 |
data_visible_classifier_t *current = &(fake_input_data.visible_classifiers[c_idx]); |
| 84 |
|
| 85 |
data_visible_classifier_init_empty ( current ); |
| 86 |
|
| 87 |
data_classifier_t *classifier = data_visible_classifier_get_classifier_ptr ( current ); |
| 88 |
data_diagramelement_t *diagele = data_visible_classifier_get_diagramelement_ptr ( current ); |
| 89 |
|
| 90 |
data_err = data_classifier_init( classifier, |
| 91 |
c_idx/2, /* id */ |
| 92 |
DATA_CLASSIFIER_TYPE_CLASS, /* main_type */ |
| 93 |
"stereotype", |
| 94 |
"name", |
| 95 |
"description", |
| 96 |
1000*c_idx, /* x_order */ |
| 97 |
-300*c_idx, /* y_order */ |
| 98 |
4000*c_idx, /* list_order */ |
| 99 |
"19e0f597-9b9d-4e27-b69d-fc648370ae46" |
| 100 |
); |
| 101 |
TEST_ENVIRONMENT_ASSERT( data_err == U8_ERROR_NONE ); |
| 102 |
|
| 103 |
data_err = data_diagramelement_init( diagele, |
| 104 |
c_idx, /* id */ |
| 105 |
3, /* diagram_id */ |
| 106 |
c_idx/2, /* classifier_id */ |
| 107 |
DATA_DIAGRAMELEMENT_FLAG_ANONYMOUS_INSTANCE | DATA_DIAGRAMELEMENT_FLAG_EMPHASIS, /* display_flags */ |
| 108 |
DATA_ROW_VOID, /* focused_feature_id */ |
| 109 |
"bcb8a819-90c7-49ad-b21d-feccfd5bcf96" |
| 110 |
); |
| 111 |
TEST_ENVIRONMENT_ASSERT( data_err == U8_ERROR_NONE ); |
| 112 |
|
| 113 |
TEST_ENVIRONMENT_ASSERT( data_visible_classifier_is_valid( current ) ); |
| 114 |
} |
| 115 |
|
| 116 |
const uint_fast32_t classifier_mod = ((classifiers/2)==0) ? 1 : (classifiers/2); |
| 117 |
|
| 118 |
/* initialize the fake_input_data.features */ |
| 119 |
fake_input_data.feature_count = features; |
| 120 |
for ( uint_fast32_t f_idx = 0; f_idx < features; f_idx ++ ) |
| 121 |
{ |
| 122 |
data_feature_t *current = &(fake_input_data.features[f_idx]); |
| 123 |
|
| 124 |
data_err = data_feature_init( current, |
| 125 |
f_idx, /* feature_id */ |
| 126 |
DATA_FEATURE_TYPE_OPERATION, /* feature_main_type */ |
| 127 |
f_idx % classifier_mod, /* classifier_id */ |
| 128 |
"feature_key", |
| 129 |
"feature_value", |
| 130 |
"feature_description", |
| 131 |
6000*f_idx, /* list_order */ |
| 132 |
"17c18bbd-c1d3-438d-bd85-5ec2704f8511" |
| 133 |
); |
| 134 |
TEST_ENVIRONMENT_ASSERT( data_err == U8_ERROR_NONE ); |
| 135 |
|
| 136 |
TEST_ENVIRONMENT_ASSERT( data_feature_is_valid( current ) ); |
| 137 |
} |
| 138 |
|
| 139 |
/* initialize the fake_input_data.relationships */ |
| 140 |
fake_input_data.relationship_count = relationships; |
| 141 |
for ( uint_fast32_t r_idx = 0; r_idx < relationships; r_idx ++ ) |
| 142 |
{ |
| 143 |
data_relationship_t *current = &(fake_input_data.relationships[r_idx]); |
| 144 |
|
| 145 |
data_err = data_relationship_init( current, |
| 146 |
r_idx, /* relationship_id */ |
| 147 |
r_idx % classifier_mod, /* from_classifier_id */ |
| 148 |
DATA_ROW_VOID, /* from_feature_id */ |
| 149 |
(r_idx*r_idx) % classifier_mod, /* to_classifier_id */ |
| 150 |
DATA_ROW_VOID, /* to_feature_id */ |
| 151 |
DATA_RELATIONSHIP_TYPE_UML_ASSOCIATION, /* relationship_main_type */ |
| 152 |
"stereo_t", /* stereotype */ |
| 153 |
"relationship_name", |
| 154 |
"relationship_description", |
| 155 |
1500*r_idx, /* list_order */ |
| 156 |
"a0feb041-647e-422f-a4ff-2e6647c08f77" |
| 157 |
); |
| 158 |
TEST_ENVIRONMENT_ASSERT( data_err == U8_ERROR_NONE ); |
| 159 |
|
| 160 |
TEST_ENVIRONMENT_ASSERT( data_relationship_is_valid( current ) ); |
| 161 |
} |
| 162 |
|
| 163 |
data_visible_set_update_containment_cache ( &fake_input_data ); |
| 164 |
|
| 165 |
TEST_ENVIRONMENT_ASSERT ( data_visible_set_is_valid ( &fake_input_data ) ); |
| 166 |
return &fake_input_data; |
| 167 |
return TEST_CASE_RESULT_OK; |
| 168 |
} |
| 169 |
|
| 170 |
static const int DUPLICATE_PARENT_CLASSIFIER=2; |
| 171 |
static const int DUPLICATE_FROM_CLASSIFIER=2; |
| 172 |
static const int DUPLICATE_TO_CLASSIFIER=2; |
| 173 |
|
| 174 |
static test_case_result_t test_empty_model( test_fixture_t *fix ) |
| 175 |
{ |
| 176 |
data_visible_set_t* empty_input_data; |
| 177 |
empty_input_data = init_empty_input_data(); |
| 178 |
|
| 179 |
static layout_visible_set_t testee; |
| 180 |
layout_visible_set_init( &testee, empty_input_data ); |
| 181 |
TEST_EXPECT( NULL != layout_visible_set_get_diagram_ptr ( &testee ) ) |
| 182 |
TEST_EXPECT_EQUAL_INT( 0, layout_visible_set_get_visible_classifier_count ( &testee ) ); |
| 183 |
TEST_EXPECT_EQUAL_INT( 0, layout_visible_set_get_feature_count ( &testee ) ); |
| 184 |
TEST_EXPECT_EQUAL_INT( 0, layout_visible_set_get_relationship_count ( &testee ) ); |
| 185 |
TEST_EXPECT ( ! layout_visible_set_is_consistent( &testee ) ); |
| 186 |
|
| 187 |
data_visible_set_t *fake_input_data; |
| 188 |
fake_input_data = init_fake_input_data(0,10,10); |
| 189 |
|
| 190 |
layout_visible_set_reinit( &testee, fake_input_data ); |
| 191 |
TEST_EXPECT( NULL != layout_visible_set_get_diagram_ptr ( &testee ) ); |
| 192 |
TEST_EXPECT_EQUAL_INT( 0, layout_visible_set_get_visible_classifier_count ( &testee ) ); |
| 193 |
TEST_EXPECT_EQUAL_INT( 0, layout_visible_set_get_feature_count ( &testee ) ); |
| 194 |
TEST_EXPECT_EQUAL_INT( 0, layout_visible_set_get_relationship_count ( &testee ) ); |
| 195 |
TEST_EXPECT ( layout_visible_set_is_consistent( &testee ) ); |
| 196 |
|
| 197 |
layout_visible_set_destroy( &testee ); |
| 198 |
return TEST_CASE_RESULT_OK; |
| 199 |
} |
| 200 |
|
| 201 |
static test_case_result_t test_normal_model( test_fixture_t *fix ) |
| 202 |
{ |
| 203 |
data_visible_set_t *fake_input_data; |
| 204 |
fake_input_data = init_fake_input_data(15,30,20); |
| 205 |
/* make the 0-th relation a from-feature-to-feature relation: */ |
| 206 |
data_relationship_t *linked_rel = data_visible_set_get_relationship_ptr ( fake_input_data, 0 /*index*/ ); |
| 207 |
data_relationship_set_from_feature_row_id ( linked_rel, 0 /* not DATA_ROW_VOID */ ); |
| 208 |
data_relationship_set_to_feature_row_id ( linked_rel, 0 /* not DATA_ROW_VOID */ ); |
| 209 |
|
| 210 |
static layout_visible_set_t testee; |
| 211 |
layout_visible_set_init( &testee, fake_input_data ); |
| 212 |
TEST_EXPECT( NULL != layout_visible_set_get_diagram_ptr ( &testee ) ); |
| 213 |
TEST_EXPECT_EQUAL_INT( 15, layout_visible_set_get_visible_classifier_count ( &testee ) ); |
| 214 |
TEST_EXPECT_EQUAL_INT( 30*DUPLICATE_PARENT_CLASSIFIER, layout_visible_set_get_feature_count ( &testee ) ); |
| 215 |
TEST_EXPECT_EQUAL_INT( 20*DUPLICATE_FROM_CLASSIFIER*DUPLICATE_TO_CLASSIFIER, layout_visible_set_get_relationship_count ( &testee ) ); |
| 216 |
TEST_EXPECT ( layout_visible_set_is_consistent( &testee ) ); |
| 217 |
|
| 218 |
layout_visible_set_destroy( &testee ); |
| 219 |
return TEST_CASE_RESULT_OK; |
| 220 |
} |
| 221 |
|
| 222 |
static test_case_result_t test_too_big_model( test_fixture_t *fix ) |
| 223 |
{ |
| 224 |
data_visible_set_t *fake_input_data; |
| 225 |
fake_input_data = init_fake_input_data( DATA_VISIBLE_SET_MAX_CLASSIFIERS, |
| 226 |
DATA_VISIBLE_SET_MAX_FEATURES, |
| 227 |
DATA_VISIBLE_SET_MAX_RELATIONSHIPS |
| 228 |
); |
| 229 |
|
| 230 |
static layout_visible_set_t testee; |
| 231 |
layout_visible_set_init( &testee, fake_input_data ); |
| 232 |
TEST_EXPECT( NULL != layout_visible_set_get_diagram_ptr ( &testee ) ); |
| 233 |
TEST_EXPECT_EQUAL_INT( DATA_VISIBLE_SET_MAX_CLASSIFIERS, layout_visible_set_get_visible_classifier_count ( &testee ) ); |
| 234 |
TEST_EXPECT_EQUAL_INT( LAYOUT_VISIBLE_SET_MAX_FEATURES, layout_visible_set_get_feature_count ( &testee ) ); |
| 235 |
TEST_EXPECT_EQUAL_INT( LAYOUT_VISIBLE_SET_MAX_RELATIONSHIPS, layout_visible_set_get_relationship_count ( &testee ) ); |
| 236 |
TEST_EXPECT ( layout_visible_set_is_consistent( &testee ) ); |
| 237 |
|
| 238 |
layout_visible_set_destroy( &testee ); |
| 239 |
return TEST_CASE_RESULT_OK; |
| 240 |
} |
| 241 |
|
| 242 |
static test_case_result_t test_inconsistent_model( test_fixture_t *fix ) |
| 243 |
{ |
| 244 |
data_visible_set_t *fake_input_data; |
| 245 |
fake_input_data = init_fake_input_data(5,5,5); |
| 246 |
/* make some wrong ids and links */ |
| 247 |
data_feature_t *illegal_feat1 = data_visible_set_get_feature_ptr ( fake_input_data, 4 /*index*/ ); |
| 248 |
data_feature_set_classifier_row_id ( illegal_feat1, 12000 /*non-existing classifier_id*/ ); |
| 249 |
data_relationship_t *illegal_rel1 = data_visible_set_get_relationship_ptr ( fake_input_data, 0 /*index*/ ); |
| 250 |
data_relationship_set_from_feature_row_id ( illegal_rel1, 1 /* feature id 1 does not belong to from classifier */ ); |
| 251 |
data_relationship_set_to_feature_row_id ( illegal_rel1, 0 /* not DATA_ROW_VOID */ ); |
| 252 |
data_relationship_t *illegal_rel2 = data_visible_set_get_relationship_ptr ( fake_input_data, 1 /*index*/ ); |
| 253 |
data_relationship_set_from_classifier_row_id ( illegal_rel2, 12000 /*non-existing classifier_id*/ ); |
| 254 |
data_relationship_t *illegal_rel3 = data_visible_set_get_relationship_ptr ( fake_input_data, 2 /*index*/ ); |
| 255 |
data_relationship_set_to_classifier_row_id ( illegal_rel3, 12000 /*non-existing classifier_id*/ ); |
| 256 |
|
| 257 |
static layout_visible_set_t testee; |
| 258 |
layout_visible_set_init( &testee, fake_input_data ); |
| 259 |
TEST_EXPECT( NULL != layout_visible_set_get_diagram_ptr ( &testee ) ); |
| 260 |
TEST_EXPECT_EQUAL_INT( 5, layout_visible_set_get_visible_classifier_count ( &testee ) ); |
| 261 |
TEST_EXPECT_EQUAL_INT( (5-1)*DUPLICATE_PARENT_CLASSIFIER, layout_visible_set_get_feature_count ( &testee ) ); |
| 262 |
TEST_EXPECT_EQUAL_INT( (5-3)*DUPLICATE_FROM_CLASSIFIER*DUPLICATE_TO_CLASSIFIER, layout_visible_set_get_relationship_count ( &testee ) ); |
| 263 |
TEST_EXPECT ( layout_visible_set_is_consistent( &testee ) ); |
| 264 |
|
| 265 |
layout_visible_set_destroy( &testee ); |
| 266 |
return TEST_CASE_RESULT_OK; |
| 267 |
} |
| 268 |
|
| 269 |
|
| 270 |
/* |
| 271 |
* Copyright 2019-2026 Andreas Warnke |
| 272 |
* |
| 273 |
* Licensed under the Apache License, Version 2.0 (the "License"); |
| 274 |
* you may not use this file except in compliance with the License. |
| 275 |
* You may obtain a copy of the License at |
| 276 |
* |
| 277 |
* http://www.apache.org/licenses/LICENSE-2.0 |
| 278 |
* |
| 279 |
* Unless required by applicable law or agreed to in writing, software |
| 280 |
* distributed under the License is distributed on an "AS IS" BASIS, |
| 281 |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 282 |
* See the License for the specific language governing permissions and |
| 283 |
* limitations under the License. |
| 284 |
*/ |