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,10 +11,7 @@
// Datei öffnen + Header prüfen + Metadaten lesen // Datei öffnen + Header prüfen + Metadaten lesen
// ===================================================== // =====================================================
static FILE *openFileAndReadHeader(const char *path, static FILE *openFileAndReadHeader(const char *path, unsigned short *count, unsigned short *width, unsigned short *height)
unsigned short *count,
unsigned short *width,
unsigned short *height)
{ {
// Schritt 1: Datei öffnen // Schritt 1: Datei öffnen
FILE *file = fopen(path, "rb"); FILE *file = fopen(path, "rb");

View File

@ -156,7 +156,7 @@ void test_openFileAndReadHeaderFailsOnZeroWidth(void)
if (file != NULL) { if (file != NULL) {
const char *fileTag = "__info2_image_file_format__"; const char *fileTag = "__info2_image_file_format__";
unsigned short count = 5; unsigned short count = 5;
unsigned short width = 0; // INVALID unsigned short width = 0;
unsigned short height = 28; unsigned short height = 28;
fwrite(fileTag, sizeof(fileTag[0]), strlen(fileTag), file); fwrite(fileTag, sizeof(fileTag[0]), strlen(fileTag), file);
@ -179,7 +179,7 @@ void test_openFileAndReadHeaderFailsOnZeroHeight(void)
const char *fileTag = "__info2_image_file_format__"; const char *fileTag = "__info2_image_file_format__";
unsigned short count = 5; unsigned short count = 5;
unsigned short width = 28; unsigned short width = 28;
unsigned short height = 0; // INVALID unsigned short height = 0;
fwrite(fileTag, sizeof(fileTag[0]), strlen(fileTag), file); fwrite(fileTag, sizeof(fileTag[0]), strlen(fileTag), file);
fwrite(&count, sizeof(unsigned short), 1, file); fwrite(&count, sizeof(unsigned short), 1, file);
@ -210,13 +210,12 @@ void test_openFileAndReadHeaderFailsOnTruncatedHeader(void)
void test_openFileAndReadHeaderFailsOnMissingCount(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"; const char *path = "testMissingCount.info2";
FILE *file = fopen(path, "wb"); FILE *file = fopen(path, "wb");
if (file != NULL) { if (file != NULL) {
const char *fileTag = "__info2_image_file_format__"; const char *fileTag = "__info2_image_file_format__";
fwrite(fileTag, sizeof(fileTag[0]), strlen(fileTag), file); fwrite(fileTag, sizeof(fileTag[0]), strlen(fileTag), file);
// count Feld nicht schreiben → EOF beim fread
fclose(file); fclose(file);
} }
@ -248,7 +247,7 @@ void test_openFileAndReadHeaderCorrectMetadataOrder(void)
if (file != NULL) { if (file != NULL) {
const char *fileTag = "__info2_image_file_format__"; const char *fileTag = "__info2_image_file_format__";
unsigned short count = 10; 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 short height = 32;
unsigned char label = 5; unsigned char label = 5;
unsigned char pixel_data[16*32]; unsigned char pixel_data[16*32];