forked from freudenreichan/info2Praktikum-NeuronalesNetz
TODO fix custom test (getPixelData should error)
This commit is contained in:
1 parent
1f08837b74
commit
d9bb6fd600
2 files changed
+50
-2
No files matched your search
@@ -35,6 +35,32 @@ static void prepareImageFile(const char *path, unsigned short int width, unsigne
|
||||
}
|
||||
}
|
||||
|
||||
static int writeImagesToFile(const char *path, GrayScaleImageSeries *series)
|
||||
{
|
||||
FILE *file = fopen(path, "wb");
|
||||
|
||||
if (file != NULL)
|
||||
{
|
||||
const char *fileTag = "__info2_image_file_format__";
|
||||
const short count = (short)series->count;
|
||||
const short width = (short)(series->images[0].width);
|
||||
const short height = (short)(series->images[0].height);
|
||||
fwrite(fileTag, sizeof(fileTag[0]), strlen(fileTag), file);
|
||||
fwrite(&count, sizeof(short), 1, file);
|
||||
fwrite(&width, sizeof(short), 1, file);
|
||||
fwrite(&height, sizeof(short), 1, file);
|
||||
|
||||
for (int i = 0; i < series->count; i++)
|
||||
{
|
||||
fwrite(series->images[i].buffer, sizeof(GrayScalePixelType), width * height, file);
|
||||
fwrite(&(series->labels[i]), sizeof(unsigned char), 1, file);
|
||||
}
|
||||
|
||||
fclose(file);
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
void test_readImagesReturnsCorrectNumberOfImages(void)
|
||||
{
|
||||
@@ -119,6 +145,25 @@ void test_readImagesFailsOnWrongFileTag(void)
|
||||
remove(path);
|
||||
}
|
||||
|
||||
// Test if the sizes specify buffers which are larger than can be read from the file
|
||||
// Errors as it runs into the end of the file
|
||||
void test_sizes_wrong(void)
|
||||
{
|
||||
const unsigned char expectedLabel = 15;
|
||||
|
||||
GrayScaleImageSeries *series = NULL;
|
||||
const char *path = "testFile.info2";
|
||||
prepareImageFile(path, 8, 8, 2, expectedLabel);
|
||||
series = readImages(path);
|
||||
series->images[0].width = series->images[0].width + 1;
|
||||
writeImagesToFile(path, series);
|
||||
|
||||
|
||||
TEST_ASSERT_NULL(readImages(path));
|
||||
remove(path);
|
||||
|
||||
}
|
||||
|
||||
void setUp(void) {
|
||||
// Falls notwendig, kann hier Vorbereitungsarbeit gemacht werden
|
||||
}
|
||||
@@ -138,6 +183,8 @@ int main()
|
||||
RUN_TEST(test_readImagesReturnsCorrectLabels);
|
||||
RUN_TEST(test_readImagesReturnsNullOnNotExistingPath);
|
||||
RUN_TEST(test_readImagesFailsOnWrongFileTag);
|
||||
RUN_TEST(test_sizes_wrong);
|
||||
|
||||
|
||||
return UNITY_END();
|
||||
}
|
||||
Reference in new issue
Block a user