Beispiel #1
0
static void test_merge_arrays(){
  int array1[2] = {5,4}; int array1_length = 2;
  int array2[3] = {1,2,3}; int array2_length = 3;
  int* array_merged = merge(array1, array1_length, array2, array2_length);

  assert(compare_arrays(array1, array_merged, array1_length));
  assert(compare_arrays(array2, (array_merged + array1_length), array2_length));
  free(array_merged);
}
Beispiel #2
0
static void test_intlist_delete(void)
{
   printf("Things!");
    setup();
   printf("Things!");
    /* Delete the integer @ index 0 in this list: [5]
     * list should become []
     */
    list2 = intlist_delete(list2, 0);
    sput_fail_unless(list2.size == 0,
                     "Delete element @ 0 in [5]\n"
                     "Verifying list size is now 0");

    /* Delete the integer @ index 0 in this list: [5, 3, 2]
     * list should become [3, 2]
     */
    list4 = intlist_delete(list4, 0);
    sput_fail_unless(list4.size == 2,
                     "Delete element @ 0 in [5 3 2]\n"
                     "Verifying list size is now 2");
    int expected1[] = {3, 2};
    sput_fail_unless(compare_arrays(list4.elems, expected1, 2),
                     "Verifying list is now [3 2]");

    teardown();
    setup();

    /* Delete the integer @ index 1 in this list: [5, 3, 2]
     * list should become [5, 2]
     */
    list4 = intlist_delete(list4, 1);
    sput_fail_unless(list4.size == 2,
                     "Delete element @ 1 in [5 3 2]\n"
                     "Verifying list size is now 2");
    int expected2[] = {5, 2};
    sput_fail_unless(compare_arrays(list4.elems, expected2, 2),
                     "Verifying list is now [5 2]");

	teardown();
	setup();

    /* Delete the integer @ index 2 in this list: [5, 3, 2]
     * list should become [5, 3]
     */
    list4 = intlist_delete(list4, 2);
    sput_fail_unless(list4.size == 2,
                     "Delete element @ 2 in [5 3 2]\n"
                     "Verifying list size is now 2");
    int expected3[] = {5, 3};
    sput_fail_unless(compare_arrays(list4.elems, expected3, 2),
                     "Verifying list is now [5 3]");

	teardown();
}
Beispiel #3
0
static void test_increase_capacity(void)
{
    /* Initialize a new list to [4, 7, 3, -2, 9] */
    intlist_t list = intlist_construct(5);
    list = intlist_append(list, 4);
    list = intlist_append(list, 7);
    list = intlist_append(list, 3);
    list = intlist_append(list, -2);
    list = intlist_append(list, 9);

    int *old_array = list.elems;

    /* Increase the list's capacity from 5 to 10. */
    list = increase_capacity(list, 10);

    sput_fail_unless(list.capacity == 10,
                     "list = intlist_construct(10);\n"
                     "Initialized list to [4 7 3 -2 9]\n"
                     "list = increase_capacity(list, 10)\n"
                     "Verifying list capacity increased from 5 to 10");
    sput_fail_unless(list.elems != old_array,
                     "Verifying that a new array was allocated");

    int expected[] = {4, 7, 3, -2, 9};
    sput_fail_unless(compare_arrays(list.elems, expected, 5),
                     "Verifying that list still contains [4 7 3 -2 9]");

    intlist_destroy(list);
}
Beispiel #4
0
static void test_modified_intlist_append(void)
{
    int expected[] = {0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20};

    /* Construct a list with capacity 10 and fill it. */

    intlist_t list = intlist_construct(10);
    for (int i = 0; i < 10; i += 1) {
        list = intlist_append(list, i * 2);
    }

    /* Now append an integer to the full list.*/

    list = intlist_append(list, 20);

    sput_fail_unless(compare_arrays(list.elems, expected, 11),
                     "list = intlist_construct(10);\n"
		             "Initialized list to [0 2 4 6 8 10 12 14 16 18]\n"
                     "list = intlist_append(list, 20);\n"
		             "Verifying list is now [0 2 4 6 8 10 12 14 16 18 20]");
    sput_fail_unless(list.size == 11,
                     "Verifying list size is now 11");
    sput_fail_unless(list.capacity == 20,
                     "Verifying list capacity is now 20");

    intlist_destroy(list);
}
Beispiel #5
0
static void test_quicksort(){
  int array[4] = {2,9,1,5};
  int expected_sorted_array[4] = {1,2,5,9};
  int *array_sorted = quicksort(array, 4);

  assert(compare_arrays(array_sorted, expected_sorted_array, 4));
}
Beispiel #6
0
/*
** Gets the percentage of difference between two structures of line,
** compares word by word.
** Return the percentage of difference between two strings,
** word by word algorithm.
**
** @param: line1 - structure of line one
** @param: line2 - structure of line two
** @return: Integer - returns the comparison value in percentage
** or -1 in case of null strings
*/
int	compare_words_strings(const s_line *line1, const s_line *line2)
{
  int result = 0;

  if (!line1 || !line2) 
    return -1;
  if (!line1->words || !line2->words)
    return -1;

  result = (line1->nb_words > line2->nb_words ?
	    compare_arrays(line1->words, line2->words) :
	    compare_arrays(line2->words, line1->words));
  if ((line1->nb_words > 0 || line2->nb_words > 0) && result >= 0)
    return ((result * 100) / (line1->nb_words > line2->nb_words ?
			      line1->nb_words : line2->nb_words));
  return -1;
}
Beispiel #7
0
static void test_merge_arrays_one_empty(){
  int array1[2] = {5,4};
  int array1_length = 2;
  int* array_merged = merge(array1, array1_length, NULL, 0);

  assert(array_merged != array1);
  assert(compare_arrays(array1, array_merged, array1_length));
  free(array_merged);
}
Beispiel #8
0
static void test_copy_array(){
  int array[3] = {1,2,3};
  int array_length = 3;
  int* array_copy = copy_array(array, array_length);

  assert(array_copy != array);
  assert(compare_arrays(array, array_copy, array_length));
  free(array_copy);
}
Beispiel #9
0
static void test_normalize(void)
{
	double samples[] = {-2.0, -1.0, 2.0, 0.0};
    double expected[] = {0.0, 0.25, 1.0, 0.5};

    normalize(samples, 4);

    sput_fail_unless(compare_arrays(samples, expected, 4), 
                     "\nnormalize({-2.0, -1.0, 2.0, 0.0}) ==> "
                     "{0.0, 0.25, 1.0, 0.5}");
}
Beispiel #10
0
Maybe<Glyph> Recipes::build(const std::array<Glyph,30>& g) {
  Maybe<Glyph> result;
  for(int i = 0; i < 6; ++i) {
    std::cout << "volta " << i << std::endl;
    if(compare_arrays(g, _recipes[i])) {
      std::cout << "wtf " << std::endl;
      result.valid = true;
      result.value = _glyphs[i];
      return result;
    }
  }
  result.valid = false;
  return result;
}
Beispiel #11
0
void test_traversal()
{
	char input[10][53] = {"8,-4,2,1,$,3,$,6,5,$,7,$,12,10,9,$,11,$,14,13,$,15,$",
								  "8,4,2,$,6,5,$,7,$,12,10,9,$,11,$,14,13,$,15,$",
								  "8,4,2,1,$,3,$,6,5,$,7,$,12,10,9,$,11,$,-",
								  "5,4,2,$,1,$,3,6,$,7,$",
								  "5,4,$,3,6,$,7,$",
								  "5,4,2,$,1,$,3,$",
								  "1,2,$,3,$",
								  "5,$",
								  "1,2,$,-",
								  '\0'
								};

	int output[10][16] ={
						{8,-4,2,1,3,6,5,7,12,10,9,11,14,13,15},
						{8,4,2,6,5,7,12,10,9,11,14,13,15},
						{8,4,2,1,3,6,5,7,12,10,9,11},
						{5,4,2,1,3,6,7},
						{5,4,3,6,7},
						{5,4,2,1,3},
						{1,2,3},
						{5},
						{1,2},
						NULL
						}; 
	int iter_loop;
	for(iter_loop=0;iter_loop<10;iter_loop++)
	{
		int index;
		NODE *root = (NODE*)malloc(sizeof(NODE));

		index = next_element_in_string(input[iter_loop],0);
		root->data = create_number(input[iter_loop],index);
		index = next_element_in_string(input[iter_loop],index);
		construct_tree(root,input[iter_loop],index);

		int *traversal_array;
		traversal_array = driver_of_traverse_arrays(root);
		(compare_arrays(traversal_array,output[iter_loop]) == 1)?printf("ACCEPTED\n"):printf("REJECTED\n");
		free(traversal_array);
		delete_tree(root);
	}
}
/**
 * Decodes the configuration node into a compound.
 *
 * @param p0 the destination (internals memory) (Hand over as reference!)
 * @param p1 the destination count
 * @param p2 the destination size
 * @param p3 the source (libxml2 xml node)
 * @param p4 the source count
 */
void decode_configuration_node(void* p0, void* p1, void* p2, const void* p3, const void* p4) {

    if (p3 != NULL_POINTER) {

        xmlNode* s = (xmlNode*) p3;

        if (p0 != NULL_POINTER) {

            void** d = (void**) p0;

            if (s != NULL_POINTER) {

                log_message_debug("Decode configuration node.");

                // Determine first child node.
                xmlNode* c = s->children;
                // The source name.
                void* sn = NULL_POINTER;
                int snc = 0;
                // The source channel.
                void* sc = NULL_POINTER;
                int scc = 0;
                // The source abstraction.
                void* sa = NULL_POINTER;
                int sac = 0;
                // The source model.
                void* sm = NULL_POINTER;
                int smc = 0;
                // The destination model.
                void* dm = NULL_POINTER;
                int* dmc = INTEGER_NULL_POINTER;
                int* dms = INTEGER_NULL_POINTER;
                // The comparison result.
                int r = 0;

                while (1) {

                    if (c == NULL_POINTER) {

                        break;
                    }

                    if (c->type == XML_ELEMENT_NODE) {

                        // Decode child node properties.
                        decode_cybol_property(
                            (void*) &sn, (void*) &snc, (void*) &sc, (void*) &scc,
                            (void*) &sa, (void*) &sac, (void*) &sm, (void*) &smc,
                            (void*) c);

        fprintf(stderr, "sn: %s\n", (char*) sn);
        fprintf(stderr, "snc: %i\n", snc);
        fprintf(stderr, "sc: %s\n", (char*) sc);
        fprintf(stderr, "scc: %i\n", scc);
        fprintf(stderr, "sa: %s\n", (char*) sa);
        fprintf(stderr, "sac: %i\n", sac);
        fprintf(stderr, "sm: %s\n", (char*) sm);
        fprintf(stderr, "smc: %i\n", smc);

                        if (r != 1) {

                            compare_arrays(sn, (void*) &snc, (void*) STARTUP_CHANNEL_CONFIGURATION_NAME, (void*) STARTUP_CHANNEL_CONFIGURATION_NAME_COUNT, (void*) &r, (void*) CHARACTER_ARRAY);

                            if (r == 1) {

                                log_message_debug("Found startup channel configuration name.");

                                // Create destination model.
                                create_integer((void*) &dmc);
                                *dmc = 0;
                                create_integer((void*) &dms);
                                *dms = 0;
                                create_model((void*) &dm, (void*) dmc, (void*) dms,
                                    sm, (void*) &smc,
                                    sa, (void*) &sac,
                                    sc, (void*) &scc);

                                // Set configuration parameter in internals memory.
                                set_array_elements(*d, (void*) STARTUP_CHANNEL_INTERNAL, (void*) &dm, (void*) ONE_NUMBER, (void*) POINTER_ARRAY);
                                set_array_elements(*d, (void*) STARTUP_CHANNEL_COUNT_INTERNAL, (void*) &dmc, (void*) ONE_NUMBER, (void*) POINTER_ARRAY);
                                set_array_elements(*d, (void*) STARTUP_CHANNEL_SIZE_INTERNAL, (void*) &dms, (void*) ONE_NUMBER, (void*) POINTER_ARRAY);
                            }
                        }

                        if (r != 1) {

                            compare_arrays(sn, (void*) &snc, (void*) STARTUP_ABSTRACTION_CONFIGURATION_NAME, (void*) STARTUP_ABSTRACTION_CONFIGURATION_NAME_COUNT, (void*) &r, (void*) CHARACTER_ARRAY);

                            if (r == 1) {

                                log_message_debug("Found startup abstraction configuration name.");

                                // Create destination model.
                                create_integer((void*) &dmc);
                                *dmc = 0;
                                create_integer((void*) &dms);
                                *dms = 0;
                                create_model((void*) &dm, (void*) dmc, (void*) dms,
                                    sm, (void*) &smc,
                                    sa, (void*) &sac,
                                    sc, (void*) &scc);

                                // Set configuration parameter in internals memory.
                                set_array_elements(*d, (void*) STARTUP_ABSTRACTION_INTERNAL, (void*) &dm, (void*) ONE_NUMBER, (void*) POINTER_ARRAY);
                                set_array_elements(*d, (void*) STARTUP_ABSTRACTION_COUNT_INTERNAL, (void*) &dmc, (void*) ONE_NUMBER, (void*) POINTER_ARRAY);
                                set_array_elements(*d, (void*) STARTUP_ABSTRACTION_SIZE_INTERNAL, (void*) &dms, (void*) ONE_NUMBER, (void*) POINTER_ARRAY);
                            }
                        }

                        if (r != 1) {

                            compare_arrays(sn, (void*) &snc, (void*) STARTUP_MODEL_CONFIGURATION_NAME, (void*) STARTUP_MODEL_CONFIGURATION_NAME_COUNT, (void*) &r, (void*) CHARACTER_ARRAY);

                            if (r == 1) {

                                log_message_debug("Found startup model configuration name.");

                                // Create destination model.
                                create_integer((void*) &dmc);
                                *dmc = 0;
                                create_integer((void*) &dms);
                                *dms = 0;
                                create_model((void*) &dm, (void*) dmc, (void*) dms,
                                    sm, (void*) &smc,
                                    sa, (void*) &sac,
                                    sc, (void*) &scc);

                                // Set configuration parameter in internals memory.
                                set_array_elements(*d, (void*) STARTUP_MODEL_INTERNAL, (void*) &dm, (void*) ONE_NUMBER, (void*) POINTER_ARRAY);
                                set_array_elements(*d, (void*) STARTUP_MODEL_COUNT_INTERNAL, (void*) &dmc, (void*) ONE_NUMBER, (void*) POINTER_ARRAY);
                                set_array_elements(*d, (void*) STARTUP_MODEL_SIZE_INTERNAL, (void*) &dms, (void*) ONE_NUMBER, (void*) POINTER_ARRAY);
                            }
                        }

                        if (r != 1) {

                            compare_arrays(sn, (void*) &snc, (void*) UNIX_SERVER_SOCKET_ACTIVE_CONFIGURATION_NAME, (void*) UNIX_SERVER_SOCKET_ACTIVE_CONFIGURATION_NAME_COUNT, (void*) &r, (void*) CHARACTER_ARRAY);

                            if (r == 1) {

                                log_message_debug("Found unix server socket active configuration name.");

                                // Create destination model.
                                create_model((void*) &dm, (void*) ONE_NUMBER, (void*) ONE_NUMBER,
                                    sm, (void*) &smc,
                                    sa, (void*) &sac,
                                    sc, (void*) &scc);

                                // Set configuration parameter in internals memory.
                                set_array_elements(*d, (void*) UNIX_SERVER_SOCKET_ACTIVE_INTERNAL, (void*) &dm, (void*) ONE_NUMBER, (void*) POINTER_ARRAY);
                            }
                        }

                        if (r != 1) {

                            compare_arrays(sn, (void*) &snc, (void*) UNIX_SERVER_SOCKET_FILENAME_CONFIGURATION_NAME, (void*) UNIX_SERVER_SOCKET_FILENAME_CONFIGURATION_NAME_COUNT, (void*) &r, (void*) CHARACTER_ARRAY);

                            if (r == 1) {

                                log_message_debug("Found unix server socket filename configuration name.");

                                // Create destination model.
                                create_model((void*) &dm, (void*) ONE_NUMBER, (void*) ONE_NUMBER,
                                    sm, (void*) &smc,
                                    sa, (void*) &sac,
                                    sc, (void*) &scc);

                                // Set configuration parameter in internals memory.
                                set_array_elements(*d, (void*) UNIX_SERVER_SOCKET_FILENAME_INTERNAL, (void*) &dm, (void*) ONE_NUMBER, (void*) POINTER_ARRAY);
                            }
                        }

                        if (r != 1) {

                            compare_arrays(sn, (void*) &snc, (void*) TCP_SERVER_SOCKET_ACTIVE_CONFIGURATION_NAME, (void*) TCP_SERVER_SOCKET_ACTIVE_CONFIGURATION_NAME_COUNT, (void*) &r, (void*) CHARACTER_ARRAY);

                            if (r == 1) {

                                log_message_debug("Found tcp server socket active configuration name.");

                                // Create destination model.
                                create_model((void*) &dm, (void*) ONE_NUMBER, (void*) ONE_NUMBER,
                                    sm, (void*) &smc,
                                    sa, (void*) &sac,
                                    sc, (void*) &scc);

                                // Set configuration parameter in internals memory.
                                set_array_elements(*d, (void*) TCP_SERVER_SOCKET_ACTIVE_INTERNAL, (void*) &dm, (void*) ONE_NUMBER, (void*) POINTER_ARRAY);
                            }
                        }

                        if (r != 1) {

                            compare_arrays(sn, (void*) &snc, (void*) TCP_SERVER_SOCKET_PORT_CONFIGURATION_NAME, (void*) TCP_SERVER_SOCKET_PORT_CONFIGURATION_NAME_COUNT, (void*) &r, (void*) CHARACTER_ARRAY);

                            if (r == 1) {

                                log_message_debug("Found tcp server socket port configuration name.");

                                // Create destination model.
                                create_model((void*) &dm, (void*) ONE_NUMBER, (void*) ONE_NUMBER,
                                    sm, (void*) &smc,
                                    sa, (void*) &sac,
                                    sc, (void*) &scc);

                                // Set configuration parameter in internals memory.
                                set_array_elements(*d, (void*) TCP_SERVER_SOCKET_PORT_INTERNAL, (void*) &dm, (void*) ONE_NUMBER, (void*) POINTER_ARRAY);
                            }
                        }

                        if (r != 1) {

                            compare_arrays(sn, (void*) &snc, (void*) X_WINDOWS_SERVER_ACTIVE_CONFIGURATION_NAME, (void*) X_WINDOWS_SERVER_ACTIVE_CONFIGURATION_NAME_COUNT, (void*) &r, (void*) CHARACTER_ARRAY);

                            if (r == 1) {

                                log_message_debug("Found x windows server active configuration name.");

                                // Create destination model.
                                create_model((void*) &dm, (void*) ONE_NUMBER, (void*) ONE_NUMBER,
                                    sm, (void*) &smc,
                                    sa, (void*) &sac,
                                    sc, (void*) &scc);

                                // Set configuration parameter in internals memory.
                                set_array_elements(*d, (void*) X_WINDOWS_SERVER_ACTIVE_INTERNAL, (void*) &dm, (void*) ONE_NUMBER, (void*) POINTER_ARRAY);
                            }
                        }

                        // Reset source name.
                        sn = NULL_POINTER;
                        snc = 0;
                        // Reset source channel.
                        sc = NULL_POINTER;
                        scc = 0;
                        // Reset source abstraction.
                        sa = NULL_POINTER;
                        sac = 0;
                        // Reset source model.
                        sm = NULL_POINTER;
                        smc = 0;
                        // Reset destination model.
                        dm = NULL_POINTER;
                        dmc = INTEGER_NULL_POINTER;
                        dms = INTEGER_NULL_POINTER;
                        // Reset comparison result.
                        r = 0;
                    }

                    c = c->next;
                }

            } else {

//??                log_message((void*) &ERROR_LOG_LEVEL, (void*) &"Could not translate xml node. The source is null.");
            }

        } else {

//??            log_message((void*) &ERROR_LOG_LEVEL, (void*) &"Could not translate xml node. The source is null.");
        }

    } else {

//??        log_message((void*) &ERROR_LOG_LEVEL, (void*) &"Could not translate xml node. The source parameter is null.");
    }
}
Beispiel #13
0
static void test_intlist_append(void)
{
    int expected[] = {0, 2, 4, 6, 8, 10, 12, 14, 16, 18};

    intlist_t list = intlist_construct(10);

    list = intlist_append(list, 0);

    sput_fail_unless(compare_arrays(list.elems, expected, 1),
		             "list = intlist_construct(10);\n"
                     "list = intlist_append(list, 0);\n"
		             "Verifying list is now [0]");
    sput_fail_unless(list.size == 1,
                     "Verifying list size is 1");
    sput_fail_unless(list.capacity == 10,
                     "Verifying list capacity is 10");


    list = intlist_append(list, 2);

    sput_fail_unless(compare_arrays(list.elems, expected, 2),
                     "list = intlist_append(list, 0);\n"
                     "Verifying list is now [0 2]");
    sput_fail_unless(list.size == 2,
                     "Verifying list size is 2");
    sput_fail_unless(list.capacity == 10,
                     "Verifying list capacity is 10");

    intlist_destroy(list);


	list = intlist_construct(10);

	for (int i = 0; i < 9; i++) {
        list = intlist_append(list, 2 * i);
    }
    /* The list is now [0, 2, 4, ..., 16], size == 9, capacity == 10 */

    list = intlist_append(list, 18);

    sput_fail_unless(compare_arrays(list.elems, expected, 10),
                     "list = intlist_construct(10);\n"
                     "Initialized list to [0 2 4 6 8 10 12 14 16],\n"
                     "list = intlist_append(list, 18);\n"
                     "Verifying list is now [0 2 4 6 8 10 12 14 16 18]");
    sput_fail_unless(list.size == 10,
                     "Verifying list size is 10");
    sput_fail_unless(list.capacity == 10,
                     "Verifying list capacity is 10");

#ifdef notdef

    /* This test case assume that intlist_append doesn't increase
     * the capacity of a full list.
     */

    /* Now attempt to append an integer to a full list.*/

    list = intlist_append(list, 20);

    sput_fail_unless(compare_arrays(list.elems, expected, 10),
                     "list = intlist_append(list, 20);\n"
                     "Verifying list is unchanged: [0 2 4 6 8 10 12 14 16 18]");
    sput_fail_unless(list.size == 10,
                     "Verifying list size is 10");
    sput_fail_unless(list.capacity == 10,
                     "Verifying list capacity is 10");
#endif

    intlist_destroy(list);
}
Beispiel #14
0
// Calculates the Tanimoto coefficient between two sets.
static VALUE Similarity_tanimoto_coefficient(VALUE self, VALUE data1, VALUE data2) {
  return compare_arrays(data1, data2, tanimoto_coefficient);
}
Beispiel #15
0
static VALUE Similarity_dice_coefficient(VALUE self, VALUE data1, VALUE data2) {
  return compare_arrays(data1, data2, dice_coefficient);
}
Beispiel #16
0
/**
 * Tests the knowledge model.
 *
 * The knowledge model is the root of a compound (tree).
 * But also a part of the knowledge model can be handed over,
 * in which case that part and its parts will be printed on screen.
 *
 * @param p0 the knowledge model
 * @param p1 the knowledge model count
 * @param level the level for the tree
 */
void test_knowledge_model(const void* p0, const void* p1, int level) {

    fputs("Test knowledge model:\n", stdout);

    char prefix[level * 3 + 1];
    int level_count;
    int char_count;

    for (level_count = 0; level_count < level; level_count++) {

        for (char_count = 0; char_count <= 2; char_count++) {

            prefix[level_count * 3 + char_count] = '_';
        }
    }

    prefix[level * 3] = '\0';
    level++;

    if (p1 != NULL_POINTER) {

        int* c = (int*) p1;

        // The loop index.
        int i = 0;
        // The element name.
        void** n = POINTER_NULL_POINTER;
        void** nc = POINTER_NULL_POINTER;
        void** ns = POINTER_NULL_POINTER;
        // The element abstraction.
        void** a = POINTER_NULL_POINTER;
        void** ac = POINTER_NULL_POINTER;
        void** as = POINTER_NULL_POINTER;
        // The element model.
        void** m = POINTER_NULL_POINTER;
        void** mc = POINTER_NULL_POINTER;
        void** ms = POINTER_NULL_POINTER;
        // The element details.
        void** d = POINTER_NULL_POINTER;
        void** dc = POINTER_NULL_POINTER;
        void** ds = POINTER_NULL_POINTER;
        // The comparison result.
        int r = 0;

        while (1) {

            if (i >= *c) {

                break;
            }

            // Get element name.
            get_compound_element_name_by_index(p0, p1, (void*) &i,
                (void*) &n, (void*) &nc, (void*) &ns);

            // Get element.
            get_compound_element_by_index(p0, p1, (void*) &i,
                (void*) &a, (void*) &ac, (void*) &as,
                (void*) &m, (void*) &mc, (void*) &ms,
                (void*) &d, (void*) &dc, (void*) &ds);

            // Print element name.
            fprintf(stderr, "name:              %s%s\n", prefix, *n);
            fprintf(stderr, "name count:        %s%i\n", prefix, **((int**) nc));
            fprintf(stderr, "name size:         %s%i\n", prefix, **((int**) ns));

            // Print element abstraction.
            fprintf(stderr, "abstraction:       %s%s\n", prefix, *a);
            fprintf(stderr, "abstraction count: %s%i\n", prefix, **((int**) ac));
            fprintf(stderr, "abstraction size:  %s%i\n", prefix, **((int**) as));

            // Handle element model.
            if (r != 1) {

                compare_arrays((void*) *a, (void*) *ac, (void*) COMPOUND_ABSTRACTION, (void*) COMPOUND_ABSTRACTION_COUNT, (void*) &r, (void*) CHARACTER_ARRAY);

                if (r == 1) {

                    fprintf(stderr, "model (compound): %s\n", "hierarchical, see below");
                    test_knowledge_model((void*) *m, (void*) *mc, level);
                }
            }

            if (r != 1) {

                compare_arrays((void*) *a, (void*) *ac, (void*) OPERATION_ABSTRACTION, (void*) OPERATION_ABSTRACTION_COUNT, (void*) &r, (void*) CHARACTER_ARRAY);

                if (r == 1) {

                    fprintf(stderr, "model (operation):         %s\n", (char*) *m);
                    fprintf(stderr, "model (operation) count:   %i\n", **((int**) mc));
                    fprintf(stderr, "model (operation) size:    %i\n", **((int**) ms));
                }
            }

            if (r != 1) {

                compare_arrays((void*) *a, (void*) *ac, (void*) STRING_ABSTRACTION, (void*) STRING_ABSTRACTION_COUNT, (void*) &r, (void*) CHARACTER_ARRAY);

                if (r == 1) {

                    fprintf(stderr, "model (string):             %s\n", (char*) *m);
                    fprintf(stderr, "model (string) count:       %i\n", **((int**) mc));
                    fprintf(stderr, "model (string) size:        %i\n", **((int**) ms));
                }
            }

            if (r != 1) {

                compare_arrays((void*) *a, (void*) *ac, (void*) INTEGER_ABSTRACTION, (void*) INTEGER_ABSTRACTION_COUNT, (void*) &r, (void*) CHARACTER_ARRAY);

                if (r == 1) {

                    fprintf(stderr, "model (integer):            %i\n", **((int**) m));
                }
            }

            // Handle element details.
            if (d != NULL_POINTER) {

                fprintf(stderr, "details: %s\n", "hierarchical, see below");
                test_knowledge_model((void*) *d, (void*) *dc, level);
            }

            // Reset element name.
            n = POINTER_NULL_POINTER;
            nc = POINTER_NULL_POINTER;
            ns = POINTER_NULL_POINTER;
            // Reset element abstraction.
            a = POINTER_NULL_POINTER;
            ac = POINTER_NULL_POINTER;
            as = POINTER_NULL_POINTER;
            // Reset element model.
            m = POINTER_NULL_POINTER;
            mc = POINTER_NULL_POINTER;
            ms = POINTER_NULL_POINTER;
            // Reset element details.
            d = POINTER_NULL_POINTER;
            dc = POINTER_NULL_POINTER;
            ds = POINTER_NULL_POINTER;
            // Reset comparison result.
            r = 0;

            i++;
        }

    } else {

        fputs("ERROR: Could not test knowledge model. The knowledge model is null.", stdout);
    }
}
Beispiel #17
0
/**
 * Serializes the document model according to the given document type
 * and creates a byte stream from it.
 *
 * @param p0 the destination (Hand over as reference!)
 * @param p1 the destination count
 * @param p2 the destination size
 * @param p3 the source
 * @param p4 the source count
 * @param p5 the type
 * @param p6 the type count
 */
void serialize(void* p0, void* p1, void* p2, const void* p3, const void* p4,
               const void* p5, const void* p6) {

    // The comparison result.
    int r = 0;

    if (r != 1) {

        compare_arrays(p5, p6, (void*) CYBOL_ABSTRACTION, (void*) CYBOL_ABSTRACTION_COUNT, (void*) &r, (void*) CHARACTER_ARRAY);

        if (r == 1) {

            serialize_xml(p0, p1, p2, p3, p4);
        }
    }

    if (r != 1) {

        compare_arrays(p5, p6, (void*) OPERATION_ABSTRACTION, (void*) OPERATION_ABSTRACTION_COUNT, (void*) &r, (void*) CHARACTER_ARRAY);

        if (r == 1) {

            serialize_string(p0, p1, p2, p3, p4);
        }
    }

    if (r != 1) {

        compare_arrays(p5, p6, (void*) STRING_ABSTRACTION, (void*) STRING_ABSTRACTION_COUNT, (void*) &r, (void*) CHARACTER_ARRAY);

        if (r == 1) {

            serialize_string(p0, p1, p2, p3, p4);
        }
    }

    if (r != 1) {

        compare_arrays(p5, p6, (void*) BOOLEAN_ABSTRACTION, (void*) BOOLEAN_ABSTRACTION_COUNT, (void*) &r, (void*) CHARACTER_ARRAY);

        if (r == 1) {

            serialize_boolean(p0, p1, p2, p3, p4);
        }
    }

    if (r != 1) {

        compare_arrays(p5, p6, (void*) INTEGER_ABSTRACTION, (void*) INTEGER_ABSTRACTION_COUNT, (void*) &r, (void*) CHARACTER_ARRAY);

        if (r == 1) {

            serialize_integer(p0, p1, p2, p3, p4);
        }
    }

    if (r != 1) {

        compare_arrays(p5, p6, (void*) VECTOR_ABSTRACTION, (void*) VECTOR_ABSTRACTION_COUNT, (void*) &r, (void*) CHARACTER_ARRAY);

        if (r == 1) {

            serialize_vector(p0, p1, p2, p3, p4);
        }
    }

    if (r != 1) {

        compare_arrays(p5, p6, (void*) DOUBLE_ABSTRACTION, (void*) DOUBLE_ABSTRACTION_COUNT, (void*) &r, (void*) CHARACTER_ARRAY);

        if (r == 1) {

            serialize_double(p0, p1, p2, p3, p4);
        }
    }

    if (r != 1) {

        compare_arrays(p5, p6, (void*) FRACTION_ABSTRACTION, (void*) FRACTION_ABSTRACTION_COUNT, (void*) &r, (void*) CHARACTER_ARRAY);

        if (r == 1) {

            serialize_fraction(p0, p1, p2, p3, p4);
        }
    }

    if (r != 1) {

        compare_arrays(p5, p6, (void*) COMPLEX_ABSTRACTION, (void*) COMPLEX_ABSTRACTION_COUNT, (void*) &r, (void*) CHARACTER_ARRAY);

        if (r == 1) {

            serialize_complex(p0, p1, p2, p3, p4);
        }
    }

    if (r != 1) {

        compare_arrays(p5, p6, (void*) TIME_ABSTRACTION, (void*) TIME_ABSTRACTION_COUNT, (void*) &r, (void*) CHARACTER_ARRAY);

        if (r == 1) {

            serialize_time(p0, p1, p2, p3, p4);
        }
    }

    //
    // CONFIGURATION_ABSTRACTION
    //
    // CAUTION! Parameters of the internals memory MUST NOT be written
    // to the configuration file which was given at command line!
    // The CYBOI configuration file can only be edited MANUALLY.
    //

    //?? Later, distinguish file types according to abstraction,
    //?? for example xml, html, sxi, txt, rtf,
    //?? adl (from OpenEHR), KIF, ODL etc.!
    //?? For now, only the cybol file format is considered.
}
Beispiel #18
0
/**
 * Parses the byte stream according to the given document type
 * and creates a document model from it.
 *
 * @param p0 the destination (Hand over as reference!)
 * @param p1 the destination count
 * @param p2 the destination size
 * @param p3 the source
 * @param p4 the source count
 * @param p5 the type
 * @param p6 the type count
 */
void parse(void* p0, void* p1, void* p2, const void* p3, const void* p4,
           const void* p5, const void* p6) {

    // The comparison result.
    int r = 0;

    if (r != 1) {

        compare_arrays(p5, p6, (void*) CYBOL_ABSTRACTION, (void*) CYBOL_ABSTRACTION_COUNT, (void*) &r, (void*) CHARACTER_ARRAY);

        if (r == 1) {

            parse_xml(p0, p1, p2, p3, p4);
        }
    }

    if (r != 1) {

        compare_arrays(p5, p6, (void*) OPERATION_ABSTRACTION, (void*) OPERATION_ABSTRACTION_COUNT, (void*) &r, (void*) CHARACTER_ARRAY);

        if (r == 1) {

            parse_string(p0, p1, p2, p3, p4);
        }
    }

    if (r != 1) {

        compare_arrays(p5, p6, (void*) STRING_ABSTRACTION, (void*) STRING_ABSTRACTION_COUNT, (void*) &r, (void*) CHARACTER_ARRAY);

        if (r == 1) {

            parse_string(p0, p1, p2, p3, p4);
        }
    }

    if (r != 1) {

        compare_arrays(p5, p6, (void*) BOOLEAN_ABSTRACTION, (void*) BOOLEAN_ABSTRACTION_COUNT, (void*) &r, (void*) CHARACTER_ARRAY);

        if (r == 1) {

            parse_boolean(p0, p1, p2, p3, p4);
        }
    }

    if (r != 1) {

        compare_arrays(p5, p6, (void*) INTEGER_ABSTRACTION, (void*) INTEGER_ABSTRACTION_COUNT, (void*) &r, (void*) CHARACTER_ARRAY);

        if (r == 1) {

            parse_integer(p0, p1, p2, p3, p4);
        }
    }

    if (r != 1) {

        compare_arrays(p5, p6, (void*) VECTOR_ABSTRACTION, (void*) VECTOR_ABSTRACTION_COUNT, (void*) &r, (void*) CHARACTER_ARRAY);

        if (r == 1) {

            parse_vector(p0, p1, p2, p3, p4);
        }
    }

    if (r != 1) {

        compare_arrays(p5, p6, (void*) DOUBLE_ABSTRACTION, (void*) DOUBLE_ABSTRACTION_COUNT, (void*) &r, (void*) CHARACTER_ARRAY);

        if (r == 1) {

            parse_double(p0, p1, p2, p3, p4);
        }
    }

    if (r != 1) {

        compare_arrays(p5, p6, (void*) FRACTION_ABSTRACTION, (void*) FRACTION_ABSTRACTION_COUNT, (void*) &r, (void*) CHARACTER_ARRAY);

        if (r == 1) {

            parse_fraction(p0, p1, p2, p3, p4);
        }
    }

    if (r != 1) {

        compare_arrays(p5, p6, (void*) COMPLEX_ABSTRACTION, (void*) COMPLEX_ABSTRACTION_COUNT, (void*) &r, (void*) CHARACTER_ARRAY);

        if (r == 1) {

            parse_complex(p0, p1, p2, p3, p4);
        }
    }

    if (r != 1) {

        compare_arrays(p5, p6, (void*) TIME_ABSTRACTION, (void*) TIME_ABSTRACTION_COUNT, (void*) &r, (void*) CHARACTER_ARRAY);

        if (r == 1) {

            parse_time(p0, p1, p2, p3, p4);
        }
    }

    if (r != 1) {

        compare_arrays(p5, p6, (void*) CONFIGURATION_ABSTRACTION, (void*) CONFIGURATION_ABSTRACTION_COUNT, (void*) &r, (void*) CHARACTER_ARRAY);

        if (r == 1) {

            parse_xml(p0, p1, p2, p3, p4);
        }
    }

    /*??
        //?? Later, distinguish file types according to abstraction,
        //?? for example xml, html, sxi, txt, rtf,
        //?? adl (from OpenEHR), KIF, ODL etc.!
        //?? For now, only the cybol file format is considered.

        if (r != 1) {

            compare_arrays(p5, p6, (void*) SXW_ABSTRACTION, (void*) SXW_ABSTRACTION_COUNT, (void*) &r, (void*) CHARACTER_ARRAY);

            if (r == 1) {

                //?? For other kinds of file (stream) formats,
                //?? for example from special applications like Open Office,
                //?? use a similar handling like for compound above!

                //?? Images possibly also have to be handled that way.
                //?? At first, the single image parameters have to be parsed
                //?? and written into a special parameter model in memory;
                //?? then that model has to be decoded into a knowledge model!
                //?? May be this idea is rubbish and will not work!
                //?? For the beginning, better handle images as primitve types.
            }
        }
    */
}
/**
 * Gets the compound element index.
 *
 * @param p0 the compound
 * @param p1 the compound count
 * @param p2 the element name
 * @param p3 the element name count
 * @param p4 the index
 */
void get_compound_element_index(const void* p0, const void* p1, const void* p2, const void* p3, void* p4) {

    if (p4 != NULL_POINTER) {

        int* i = (int*) p4;

        if (p1 != NULL_POINTER) {

            int* cc = (int*) p1;

//??            log_message((void*) &INFO_LOG_LEVEL, (void*) &GET_COMPOUND_INDEX_MESSAGE, (void*) &GET_COMPOUND_INDEX_MESSAGE_COUNT);

            // The element names.
            void* n = NULL_POINTER;
            void* nc = NULL_POINTER;

            // Get element names.
            get_array_element(p0, (void*) &POINTER_ARRAY, (void*) &NAMES_INDEX, (void*) &n);
            get_array_element(p0, (void*) &POINTER_ARRAY, (void*) &NAMES_COUNTS_INDEX, (void*) &nc);

            // The loop variable.
            int j = 0;
            // The name.
            void* n1 = NULL_POINTER;
            // The name count.
            int nc1 = 0;
            // The comparison result.
            int r = 0;

            while (1) {

                if (j >= *cc) {

                    break;
                }

                // Get element name.
                get_array_element((void*) &n, (void*) &POINTER_ARRAY, (void*) &j, (void*) &n1);
                get_array_element((void*) &nc, (void*) &POINTER_ARRAY, (void*) &j, (void*) &nc1);

                compare_arrays(p2, p3, (void*) &n1, (void*) &nc1, (void*) &r, (void*) &CHARACTER_ARRAY);

                if (r == 1) {

                    *i = j;

                    break;
                }

                // Reset name and name count.
                n1 = NULL_POINTER;
                nc1 = 0;

                j++;
            }

        } else {

//??            log_message((void*) &ERROR_LOG_LEVEL, (void*) &COULD_NOT_GET_COMPOUND_INDEX_THE_COMPOUND_COUNT_IS_NULL_MESSAGE, (void*) &COULD_NOT_GET_COMPOUND_INDEX_THE_COMPOUND_COUNT_IS_NULL_MESSAGE_COUNT);
        }

    } else {

//??        log_message((void*) &ERROR_LOG_LEVEL, (void*) &COULD_NOT_GET_COMPOUND_INDEX_THE_NAME_COUNT_IS_NULL_MESSAGE, (void*) &COULD_NOT_GET_COMPOUND_INDEX_THE_NAME_COUNT_IS_NULL_MESSAGE_COUNT);
    }
}