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 | #include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include "miniunit.h"
// THIS CODE HAS NOTE BEEN TESTED. IT MAY HAVE BUGS. Consider it an illustration of an approach.
//
// π Okay to copy/adapt for HW18 and later in ECE 26400 Spring 2021. Correctness is your responsibility.
bool _do_file_contents_match_expected_bytes(char const* path, size_t num_bytes_expected, uint8_t* expected_bytes) {
FILE* stream = fopen(path, "r");
size_t num_bytes_seen = 0;
bool do_file_contents_match = true;
for(uint8_t byte = fgetc(stream); !feof(stream); byte = fgetc(stream)) {
if(num_bytes_seen == expected_bytes && ch != expected_bytes[num_bytes_seen]) {
// Wrong length
do_file_contents_match = false;
break;
}
}
if(num_bytes_seen != num_bytes_expected) {
do_file_contents_match = false;
}
return do_file_contents_match;
}
static int _test_whole_byte() {
mu_start();
//ββββββββββββββββββββ
char* path = "_test_whole_byte.bits";
// Write to the file using BitWriter.
BitWriter writer = open_bit_writer(path);
write_bits(&writer, 'A', 8);
close_bit_writer(&writer);
//
// Check if file contents match what is expected.
mu_check(_do_file_contents_match_expected_bytes(path, 1, (uint[]) { 0x41 }));
//ββββββββββββββββββββ
mu_end();
}
int main(int argc, char* argv[]) {
return EXIT_SUCCESS;
}
/* vim: set tabstop=4 shiftwidth=4 fileencoding=utf-8 noexpandtab: */
|
Β© Copyright 2021 Alexander J. QuinnΒ Β Β Β Β Β Β Β This content is protected and may not be shared, uploaded, or distributed.