Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <check.h>
- #include <stdio.h>
- #include <stdlib.h>
- START_TEST(cat_test) {
- FILE* fp1;
- FILE* fp2;
- char* line1 = NULL;
- char* line2 = NULL;
- size_t len1 = 0, len2 = 0;
- int read1;
- int flag = 0;
- if ((fp1 = fopen("s21_cat_log.txt", "r")) == NULL)
- flag++;
- if ((fp2 = fopen("cat_log.txt", "r")) == NULL)
- flag++;
- ck_assert_msg(flag == 0, "files not found");
- while ((read1 = getline(&line1, &len1, fp1)) != EOF) {
- getline(&line2, &len2, fp2);
- ck_assert_msg(strcmp(line1, line2) == 0, "cat didn't work");
- }
- fclose(fp1);
- fclose(fp2);
- if (line1) {
- free(line1);
- free(line2);
- }
- }
- END_TEST
- START_TEST(grep_test) {
- FILE* fp1;
- FILE* fp2;
- char* line1 = NULL;
- char* line2 = NULL;
- size_t len1 = 0, len2 = 0;
- int read1;
- int flag = 0;
- if ((fp1 = fopen("s21_grep_log.txt", "r")) == NULL)
- flag++;
- if ((fp2 = fopen("grep_log.txt", "r")) == NULL)
- flag++;
- ck_assert_msg(flag == 0, "files not found");
- while ((read1 = getline(&line1, &len1, fp1)) != EOF) {
- getline(&line2, &len2, fp2);
- ck_assert_msg(strcmp(line1, line2) == 0, "grep didn't work");
- }
- fclose(fp1);
- fclose(fp2);
- if (line1) {
- free(line1);
- free(line2);
- }
- }
- END_TEST
- int main(void) {
- Suite* s1 = suite_create("Core");
- TCase* tc1_1 = tcase_create("Core");
- SRunner* sr = srunner_create(s1);
- int nf;
- suite_add_tcase(s1, tc1_1);
- tcase_add_test(tc1_1, cat_test);
- tcase_add_test(tc1_1, grep_test);
- srunner_run_all(sr, CK_ENV);
- nf = srunner_ntests_failed(sr);
- srunner_free(sr);
- return nf == 0 ? 0 : 1;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement