void test_productGeters()
{
	Product prod;
	product_init(&prod, "Prastie", "V2.1", "China Factory");

	assert(_msize(product_GetType(&prod)) == (strlen("Prastie") + 1) * sizeof(char));
	assert(!strcmp(product_GetType(&prod), "Prastie"));

	assert(_msize(product_GetModel(&prod)) == (strlen("V2.1") + 1) * sizeof(char));
	assert(!strcmp(product_GetModel(&prod), "V2.1"));

	assert(_msize(product_GetManufacturer(&prod)) == (strlen("China Factory") + 1) * sizeof(char));
	assert(!strcmp(product_GetManufacturer(&prod), "China Factory"));

	product_destroy(&prod);
	assert(_msize(product_GetType(&prod)) == -1);
	assert(_msize(product_GetModel(&prod)) == -1);
	assert(_msize(product_GetManufacturer(&prod)) == -1);
}
void test_productCreate()
{
	Product prod;
	product_init(&prod, "Prastie", "V2.1", "China Factory");

	assert(_msize(prod.type) == (strlen("Prastie") + 1) * sizeof(char));
	assert(!strcmp(prod.type, "Prastie"));

	assert(_msize(prod.model) == (strlen("V2.1") + 1) * sizeof(char));
	assert(!strcmp(prod.model, "V2.1"));

	assert(_msize(prod.manufacturer) == (strlen("China Factory") + 1) * sizeof(char));
	assert(!strcmp(prod.manufacturer, "China Factory"));

	product_destroy(&prod);
	assert(_msize(prod.type) == -1);
	assert(_msize(prod.model) == -1);
	assert(_msize(prod.manufacturer) == -1);
}
Beispiel #3
0
int file_run(FILE* data)
{
    product* work_product = NULL;
    char *file_menu[] = {
        "Show file data;\n",
        "Add record;\n",
        "Edit record;\n",
        "Sort records;\n",
        "Delete record;\n",
        "Save & close the file;\n"
    };

    char menu_symb[] = "0";
    char work_name[NAM_LEN + 1];

    int work_line = 0;
    int menu_count = 0;
    int incorrect_choice = 1;
    int exit = 0;

    do
    {
        incorrect_choice = 1;
        system("clear");
        for(menu_count = 0; menu_count < 6; menu_count++)
            printf("%d) %s", menu_count + 1, file_menu[menu_count]);

        printf("Input the number of menu item:\n");
        while(incorrect_choice)
        {
            menu_symb[0] = getche();
            if(!strpbrk(menu_symb, "123456"))
                printf("Unknown value: %c; repeat the choice\n", menu_symb[0]);
            else
                incorrect_choice = 0;
        }

        switch(menu_symb[0])
        {
        case '1':
        {
            file_read(data);
        }
            break;
        case '2':
        {
            work_product = product_input();
            if(work_product)
            {
                sorted_insert(data, work_product);
                product_destroy(work_product);
            }
        }
            break;
        case '3':
        {
            puts("Input the name of the product to edit:");
            string_input(stdin, NAM_LEN, work_name, 0);

            work_line = name_find(data, work_name);
            if(!work_line)
                alert("\tNo such product;");
            else
            {
                work_product = product_read(data, work_line);
                deleting(data, work_line);
                product_update(work_product);
                product_write(data, work_line, work_product);
                product_destroy(work_product);
            }
        }
            break;
        case '4':
        {

        }
            break;
        case '5':
        {
            puts("Input the name of the product to delete:");
            string_input(stdin, NAM_LEN, work_name, 0);

            work_line = name_find(data, work_name);
            if(!work_line)
                alert("\tNo such product;");
            else
                deleting(data, work_line);
        }
            break;
        case '6':
        {
            file_close(data);
            exit = 1;
        }
            break;
        }

    }while(!exit);

    return menu_symb[0] - '0';
}