1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 | #include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <assert.h>
#include "miniunit.h"
// okay to copy/adapt
int _test_mu_run_success() {
printf("Running mu_run success test\n");
return 0;
}
int _test_mu_run_failure() {
printf("Running mu_run failure test\n");
return 10;
}
int _test_empty() {
mu_start();
//────────────────────
// no checks
//────────────────────
mu_end();
}
int _test_one_success() {
mu_start();
//────────────────────
mu_check(true);
//────────────────────
mu_end();
}
int _test_two_success() {
mu_start();
//────────────────────
mu_check(true);
mu_check(true);
//────────────────────
mu_end();
}
int _test_one_failure() {
mu_start();
//────────────────────
mu_check(false);
//────────────────────
mu_end();
}
int _test_two_failure() {
mu_start();
//────────────────────
mu_check(false);
mu_check(false);
//────────────────────
mu_end();
}
int _test_mu_check_parameter_or() {
mu_start();
//────────────────────
mu_check(true || true);
//────────────────────
mu_end();
}
int _test_mu_check_parameter_and() {
mu_start();
//────────────────────
mu_check(false && false);
//────────────────────
mu_end();
}
int print_message_and_return_zero() {
printf("This function was called\n");
return 0;
}
int _test_mu_check_second_failure_does_not_evaluate() {
mu_start();
//────────────────────
mu_check(false);
// the function should never evaluate
mu_check(print_message_and_return_zero() == 0);
// non-mu_check things can still run
printf("This statement runs after my checks\n");
//────────────────────
mu_end();
}
int _test_mu_check_strings_equal_equal_contents() {
mu_start();
//────────────────────
char str1[] = "Hello";
char* str2 = "Hello";
mu_check_strings_equal(str1, str2);
//────────────────────
mu_end();
}
int _test_mu_check_strings_equal_not_equal() {
mu_start();
//────────────────────
mu_check_strings_equal("Hello", "World");
//────────────────────
mu_end();
}
int main(int argc, char* argv[]) {
// with these two tests, confident mu_run works
mu_run(_test_mu_run_success);
mu_run(_test_mu_run_failure);
// full tests
mu_run(_test_empty);
mu_run(_test_one_success);
mu_run(_test_two_success);
mu_run(_test_one_failure);
mu_run(_test_two_failure);
mu_run(_test_mu_check_parameter_or);
mu_run(_test_mu_check_parameter_and);
mu_run(_test_mu_check_second_failure_does_not_evaluate);
mu_run(_test_mu_check_strings_equal_equal_contents);
mu_run(_test_mu_check_strings_equal_not_equal);
return EXIT_SUCCESS;
}
/* vim: set tabstop=4 shiftwidth=4 fileencoding=utf-8 noexpandtab: */
|
© Copyright 2024 Alexander J. Quinn & David Burnett This content is protected and may not be shared, uploaded, or distributed.