imageInputTests Kommentiert

This commit is contained in:
Nicolas Reckert 2025-11-18 01:12:09 +01:00
parent 37d6d88ddf
commit b802e24abd
2 changed files with 7 additions and 11 deletions

View File

@ -11,14 +11,11 @@
// Datei öffnen + Header prüfen + Metadaten lesen
// =====================================================
static FILE *openFileAndReadHeader(const char *path,
unsigned short *count,
unsigned short *width,
unsigned short *height)
static FILE *openFileAndReadHeader(const char *path, unsigned short *count, unsigned short *width, unsigned short *height)
{
// Schritt 1: Datei öffnen
FILE *file = fopen(path, "rb");
if (!file) {
if (!file) {
fprintf(stderr, "Error: Cannot open file '%s'\n", path);
return NULL;
}

View File

@ -132,7 +132,7 @@ void test_openFileAndReadHeaderFailsOnZeroImageCount(void)
FILE *file = fopen(path, "wb");
if (file != NULL) {
const char *fileTag = "__info2_image_file_format__";
unsigned short zero_count = 0;
unsigned short zero_count = 0;
unsigned short width = 28;
unsigned short height = 28;
@ -156,7 +156,7 @@ void test_openFileAndReadHeaderFailsOnZeroWidth(void)
if (file != NULL) {
const char *fileTag = "__info2_image_file_format__";
unsigned short count = 5;
unsigned short width = 0; // INVALID
unsigned short width = 0;
unsigned short height = 28;
fwrite(fileTag, sizeof(fileTag[0]), strlen(fileTag), file);
@ -179,7 +179,7 @@ void test_openFileAndReadHeaderFailsOnZeroHeight(void)
const char *fileTag = "__info2_image_file_format__";
unsigned short count = 5;
unsigned short width = 28;
unsigned short height = 0; // INVALID
unsigned short height = 0;
fwrite(fileTag, sizeof(fileTag[0]), strlen(fileTag), file);
fwrite(&count, sizeof(unsigned short), 1, file);
@ -210,13 +210,12 @@ void test_openFileAndReadHeaderFailsOnTruncatedHeader(void)
void test_openFileAndReadHeaderFailsOnMissingCount(void)
{
// Test: Datei hat Header aber kein count Feld
// Test: Datei hat Header aber keine Meta Daten
const char *path = "testMissingCount.info2";
FILE *file = fopen(path, "wb");
if (file != NULL) {
const char *fileTag = "__info2_image_file_format__";
fwrite(fileTag, sizeof(fileTag[0]), strlen(fileTag), file);
// count Feld nicht schreiben → EOF beim fread
fclose(file);
}
@ -248,7 +247,7 @@ void test_openFileAndReadHeaderCorrectMetadataOrder(void)
if (file != NULL) {
const char *fileTag = "__info2_image_file_format__";
unsigned short count = 10;
unsigned short width = 16; // WICHTIG: width vor height (Anzahl, Breite, Höhe)
unsigned short width = 16; // Anzahl, Breite, Höhe
unsigned short height = 32;
unsigned char label = 5;
unsigned char pixel_data[16*32];