C ordening
This commit is contained in:
BIN
C/C(extra) ExtraAssignments/Stegano/ImageCitroen2Cv.bmp
Normal file
BIN
C/C(extra) ExtraAssignments/Stegano/ImageCitroen2Cv.bmp
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 346 KiB |
BIN
C/C(extra) ExtraAssignments/Stegano/ImageRedFerrari.bmp
Normal file
BIN
C/C(extra) ExtraAssignments/Stegano/ImageRedFerrari.bmp
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 803 KiB |
BIN
C/C(extra) ExtraAssignments/Stegano/ImageTrabant.bmp
Normal file
BIN
C/C(extra) ExtraAssignments/Stegano/ImageTrabant.bmp
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 803 KiB |
BIN
C/C(extra) ExtraAssignments/Stegano/ImageYellowFerrari.bmp
Normal file
BIN
C/C(extra) ExtraAssignments/Stegano/ImageYellowFerrari.bmp
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 713 KiB |
51
C/C(extra) ExtraAssignments/Stegano/Makefile
Normal file
51
C/C(extra) ExtraAssignments/Stegano/Makefile
Normal file
@@ -0,0 +1,51 @@
|
||||
ASSIGNMENT=stegano
|
||||
|
||||
UNITY_FOLDER=./Unity
|
||||
RESOURCE_CHECK_FOLDER=./ResourceDetector
|
||||
INC_DIRS=-I$(RESOURCE_CHECK_FOLDER)
|
||||
TEST_INC_DIRS=$(INC_DIRS) -I$(UNITY_FOLDER)
|
||||
|
||||
SRC_FILES=$(ASSIGNMENT)_main.c \
|
||||
$(RESOURCE_CHECK_FOLDER)/resource_detector.c \
|
||||
$(RESOURCE_CHECK_FOLDER)/list.c \
|
||||
$(ASSIGNMENT).c
|
||||
|
||||
TEST_FILES=$(UNITY_FOLDER)/unity.c \
|
||||
$(ASSIGNMENT)_test.c \
|
||||
$(RESOURCE_CHECK_FOLDER)/resource_detector.c \
|
||||
$(RESOURCE_CHECK_FOLDER)/list.c \
|
||||
$(ASSIGNMENT).c
|
||||
|
||||
HEADER_FILES=*.h
|
||||
|
||||
TEST = $(ASSIGNMENT)_test
|
||||
|
||||
CC=gcc
|
||||
|
||||
SYMBOLS=-g -O0 -std=c99 -Wall -Werror -Wextra -pedantic -Wno-unused-parameter
|
||||
TEST_SYMBOLS=$(SYMBOLS) -DTEST
|
||||
|
||||
.PHONY: clean test
|
||||
|
||||
all: $(ASSIGNMENT) $(TEST)
|
||||
|
||||
$(ASSIGNMENT): $(SRC_FILES) $(HEADER_FILES) Makefile
|
||||
$(CC) $(INC_DIRS) $(SYMBOLS) $(SRC_FILES) -o $(ASSIGNMENT)
|
||||
|
||||
$(TEST): Makefile $(TEST_FILES) $(HEADER_FILES)
|
||||
$(CC) $(TEST_INC_DIRS) $(TEST_SYMBOLS) $(TEST_FILES) -o $(TEST)
|
||||
|
||||
clean:
|
||||
rm -f $(ASSIGNMENT) $(TEST)
|
||||
|
||||
test: $(TEST)
|
||||
@./$(TEST)
|
||||
|
||||
klocwork:
|
||||
kwcheck run
|
||||
|
||||
klocwork_after_makefile_change: clean
|
||||
kwinject make
|
||||
kwcheck create -b kwinject.out
|
||||
kwcheck import /opt/klocwork/Fontys_default.pconf
|
||||
kwcheck run
|
||||
278
C/C(extra) ExtraAssignments/Stegano/ResourceDetector/list.c
Normal file
278
C/C(extra) ExtraAssignments/Stegano/ResourceDetector/list.c
Normal file
@@ -0,0 +1,278 @@
|
||||
/* **********************************************
|
||||
* generic linked list in plain c
|
||||
* author: Freddy Hurkmans
|
||||
* date: dec 20, 2014
|
||||
* **********************************************/
|
||||
|
||||
/* ******************************************************************************
|
||||
* This list is designed using object oriented ideas, but is implemented in c.
|
||||
*
|
||||
* The idea is: you construct a list for a certain data structure (say: mystruct):
|
||||
* list_admin* mylist = construct_list(sizeof(mystruct))
|
||||
* mylist contains private data for this list implementation. You need not worry
|
||||
* about it, only give it as first parameter to each list method.
|
||||
*
|
||||
* This means you can have multiple lists at the same time, just make sure you
|
||||
* give the right list_admin structure to the list function.
|
||||
* When you're done with your list, just call the destructor: destruct_list(&mylist)
|
||||
* The destructor automatically deletes remaining list elements and the list administration.
|
||||
*
|
||||
* As this list implementation keeps its own administration in list_admin, you need
|
||||
* not worry about next pointers and such. Your structure doesn't even need pointers
|
||||
* to itself, you only need to worry about data. A valid struct could thus be:
|
||||
* typedef struct
|
||||
* {
|
||||
* int nr;
|
||||
* char text[100];
|
||||
* } mystruct;
|
||||
*
|
||||
* Adding data to the list is done using list_add_* methods, such as list_add_tail,
|
||||
* which adds data to the end of the list:
|
||||
* mystruct data = {10, "hello world!"};
|
||||
* int result = list_add_tail(mylist, &data);
|
||||
* You don't have to provide the size of your struct, you've already done that in
|
||||
* the destructor. If result < 0 list_add_* has failed (either a parameter problem
|
||||
* or malloc didn't give memory).
|
||||
*
|
||||
* You can get a pointer to your data using list_get_*, e.g. get the 2nd element:
|
||||
* mystruct* dataptr = list_get_element(admin, 1);
|
||||
* or get the last element:
|
||||
* mystruct* dataptr = list_get_last(admin);
|
||||
* If dataptr is not NULL it points to the correct data, else the operation failed.
|
||||
*
|
||||
* Searching for data in your list can be done with list_index_of*. list_index_of
|
||||
* compares the data in each list item to the given data. If they are the same, it
|
||||
* returns the index. If you want to search for an element with a certain value for
|
||||
* nr or text (see mystruct) you can implement your own compare function and use
|
||||
* list_index_of_special (check memcmp for required return values):
|
||||
* int mycompare(void* p1, void* p2, size_t size)
|
||||
* {
|
||||
* // this example doesn't need size!
|
||||
* mystruct* org = (mystruct*)p1;
|
||||
* int* nr = (int*)p2;
|
||||
* return org->nr - nr; // return 0 if they are the same
|
||||
* }
|
||||
* Say you want to search for an element that has nr 10:
|
||||
* int nr = 10;
|
||||
* int index = list_index_of_special(mylist, &nr, mycompare);
|
||||
* As noted earlier: mycompare must have the same prototype as memcmp. In fact:
|
||||
* list_index_of is a shortcut for list_index_of_special(mylist, data, memcmp).
|
||||
*
|
||||
* Finally you can delete items with list_delete_*. They should work rather
|
||||
* straight forward. If they succeed they return 0. You don't have to delete
|
||||
* all items before destructing your list.
|
||||
*
|
||||
* ******************************************************************************/
|
||||
|
||||
|
||||
#include <string.h> /* for memcmp and memcpy */
|
||||
|
||||
#include "list.h"
|
||||
|
||||
static size_t data_size(const list_admin* admin);
|
||||
static list_head* get_guaranteed_list_head_of_element_n(list_admin* admin, size_t index);
|
||||
static list_head* get_list_head_of_element_n(list_admin* admin, size_t index);
|
||||
static void remove_first_element(list_admin* admin);
|
||||
static int remove_non_first_element(list_admin* admin, size_t index);
|
||||
|
||||
/* **********************************************
|
||||
* Constructor / destructor
|
||||
* **********************************************/
|
||||
list_admin* construct_list(size_t element_size)
|
||||
{
|
||||
list_admin* admin = malloc(sizeof(*admin));
|
||||
if (admin != NULL)
|
||||
{
|
||||
admin->head = NULL;
|
||||
admin->element_size = element_size;
|
||||
admin->nr_elements = 0;
|
||||
}
|
||||
return admin;
|
||||
}
|
||||
|
||||
void destruct_list(list_admin** admin)
|
||||
{
|
||||
if ((admin != NULL) && (*admin != NULL))
|
||||
{
|
||||
while ((*admin)->head != NULL)
|
||||
{
|
||||
list_head* temp = (*admin)->head;
|
||||
(*admin)->head = (*admin)->head->next;
|
||||
free(temp);
|
||||
temp = NULL;
|
||||
}
|
||||
free(*admin);
|
||||
*admin = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
/* **********************************************
|
||||
* Public functions
|
||||
* **********************************************/
|
||||
int list_get_nr_elements(list_admin* admin)
|
||||
{
|
||||
int nr_elements = -1;
|
||||
if (admin != NULL)
|
||||
{
|
||||
nr_elements = admin->nr_elements;
|
||||
}
|
||||
return nr_elements;
|
||||
}
|
||||
|
||||
int list_add_tail(list_admin* admin, const void* data)
|
||||
{
|
||||
int result = -1;
|
||||
if ((admin != NULL) && (data != NULL))
|
||||
{
|
||||
list_head* new = malloc(data_size(admin));
|
||||
if (new != NULL)
|
||||
{
|
||||
result = 0;
|
||||
new->next = NULL;
|
||||
memcpy(new+1, data, admin->element_size);
|
||||
|
||||
if (admin->head == NULL)
|
||||
{
|
||||
admin->head = new;
|
||||
}
|
||||
else
|
||||
{
|
||||
list_head* temp = get_guaranteed_list_head_of_element_n(admin, admin->nr_elements-1);
|
||||
temp->next = new;
|
||||
}
|
||||
|
||||
admin->nr_elements++;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
void* list_get_element(list_admin* admin, size_t index)
|
||||
{
|
||||
list_head* item = get_list_head_of_element_n(admin, index);
|
||||
if(item != NULL)
|
||||
{
|
||||
item++; // user data is just beyond list_head, thus we must increase the pointer
|
||||
}
|
||||
return item;
|
||||
}
|
||||
|
||||
void* list_get_last(list_admin* admin)
|
||||
{
|
||||
list_head* item = NULL;
|
||||
if (admin != NULL)
|
||||
{
|
||||
item = list_get_element(admin, admin->nr_elements-1);
|
||||
}
|
||||
return item;
|
||||
}
|
||||
|
||||
int list_index_of(list_admin* admin, const void* data)
|
||||
{
|
||||
return list_index_of_special(admin, data, memcmp);
|
||||
}
|
||||
|
||||
int list_index_of_special(list_admin* admin, const void* data, CompareFuncPtr compare)
|
||||
{
|
||||
int index = -1;
|
||||
if ((admin != NULL) && (data != NULL) && (compare != NULL))
|
||||
{
|
||||
list_head* temp = admin->head;
|
||||
index = 0;
|
||||
while ((temp != NULL) && (compare(temp+1, data, admin->element_size) != 0))
|
||||
{
|
||||
temp = temp->next;
|
||||
index++;
|
||||
}
|
||||
if (temp == NULL)
|
||||
{
|
||||
index = -1;
|
||||
}
|
||||
}
|
||||
return index;
|
||||
}
|
||||
|
||||
int list_delete_item(list_admin* admin, size_t index)
|
||||
{
|
||||
int result = -1;
|
||||
if ((admin != NULL) && (admin->head != NULL) && (index < admin->nr_elements))
|
||||
{
|
||||
if (index == 0)
|
||||
{
|
||||
result = 0;
|
||||
remove_first_element(admin);
|
||||
}
|
||||
else
|
||||
{
|
||||
result = remove_non_first_element(admin, index);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
int list_delete_last(list_admin* admin)
|
||||
{
|
||||
int result = -1;
|
||||
if (admin != NULL)
|
||||
{
|
||||
result = list_delete_item(admin, admin->nr_elements - 1);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/* **********************************************
|
||||
* Private functions
|
||||
* **********************************************/
|
||||
static size_t data_size(const list_admin* admin)
|
||||
{
|
||||
return admin->element_size + sizeof(list_head);
|
||||
}
|
||||
|
||||
static list_head* get_guaranteed_list_head_of_element_n(list_admin* admin, size_t index)
|
||||
{
|
||||
list_head* item = admin->head;
|
||||
for (size_t i = 0; (i < index) && (item != NULL); i++)
|
||||
{
|
||||
item = item->next;
|
||||
}
|
||||
return item;
|
||||
}
|
||||
|
||||
static list_head* get_list_head_of_element_n(list_admin* admin, size_t index)
|
||||
{
|
||||
list_head* item = NULL;
|
||||
if ((admin != NULL) && (index < admin->nr_elements))
|
||||
{
|
||||
item = get_guaranteed_list_head_of_element_n(admin, index);
|
||||
}
|
||||
return item;
|
||||
}
|
||||
|
||||
static void remove_first_element(list_admin* admin)
|
||||
{
|
||||
list_head* temp = admin->head;
|
||||
admin->head = admin->head->next;
|
||||
free(temp);
|
||||
temp = NULL;
|
||||
admin->nr_elements--;
|
||||
}
|
||||
|
||||
static int remove_non_first_element(list_admin* admin, size_t index)
|
||||
{
|
||||
int result = -1;
|
||||
if (index > 0)
|
||||
{
|
||||
list_head* temp = get_list_head_of_element_n(admin, index-1);
|
||||
if ((temp != NULL) && (temp->next != NULL)) // to remove element n, element n-1 and n must exist
|
||||
{
|
||||
result = 0;
|
||||
list_head* to_delete = temp->next;
|
||||
temp->next = to_delete->next;
|
||||
free(to_delete);
|
||||
to_delete = NULL;
|
||||
admin->nr_elements--;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
52
C/C(extra) ExtraAssignments/Stegano/ResourceDetector/list.h
Normal file
52
C/C(extra) ExtraAssignments/Stegano/ResourceDetector/list.h
Normal file
@@ -0,0 +1,52 @@
|
||||
#pragma once
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
typedef struct list_head
|
||||
{
|
||||
struct list_head* next;
|
||||
} list_head;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
struct list_head* head;
|
||||
size_t element_size;
|
||||
size_t nr_elements;
|
||||
} list_admin;
|
||||
|
||||
typedef int (*CompareFuncPtr)(const void*, const void*, size_t);
|
||||
|
||||
// call the constructor before using the list:
|
||||
// list_admin* mylist = construct_list(sizeof(mystruct));
|
||||
// if mylist equals NULL, no memory could be allocated. Please don't
|
||||
// mess with the admin data, this can corrupt your data.
|
||||
list_admin* construct_list(size_t element_size);
|
||||
|
||||
// call the destructor when you're done, pass the list administration
|
||||
// as referenced parameter (the variable will be set to NULL).
|
||||
void destruct_list(list_admin** admin);
|
||||
|
||||
// Reads the number of elements in your list. Returns -1 in case of
|
||||
// errors, else the number of elements.
|
||||
int list_get_nr_elements(list_admin* admin);
|
||||
|
||||
// Add data to the end of the list. Returns -1 in case of errors, else 0
|
||||
int list_add_tail(list_admin* admin, const void* data);
|
||||
|
||||
// Returns a pointer to the requested element. Returns NULL in case of
|
||||
// errors (such as: the element does not exist).
|
||||
void* list_get_element(list_admin* admin, size_t index);
|
||||
void* list_get_last(list_admin* admin);
|
||||
|
||||
// Returns the index to the first found list element that's equal to data,
|
||||
// or -1 in case of errors (such as: not found).
|
||||
int list_index_of(list_admin* admin, const void* data);
|
||||
|
||||
// Returns the index to the first found list element for which cmp says it's,
|
||||
// equal to data, or -1 in case of errors (such as: not found). cmp must behave
|
||||
// just like memcmp, i.e.: return 0 when the data matches.
|
||||
int list_index_of_special(list_admin* admin, const void* data, CompareFuncPtr cmp);
|
||||
|
||||
// Delete an item in the list. Returns -1 in case of errors, else 0.
|
||||
int list_delete_item(list_admin* admin, size_t index);
|
||||
int list_delete_last(list_admin* admin);
|
||||
@@ -0,0 +1,270 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdbool.h>
|
||||
#include <time.h>
|
||||
//#include <malloc.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "resource_detector.h"
|
||||
|
||||
#undef malloc
|
||||
#undef free
|
||||
#undef main
|
||||
#undef fopen
|
||||
#undef fclose
|
||||
|
||||
#include "list.h"
|
||||
|
||||
#define MAGIC_CODE 0x78563412
|
||||
|
||||
#define ADDR(addr,offset) ((addr) + (offset))
|
||||
#define SET_MAGIC_CODE(addr,offset) *((int*) ADDR(addr,offset)) = MAGIC_CODE
|
||||
#define MAGIC_CODE_OK(addr,offset) (*((int*) ADDR(addr,offset)) == MAGIC_CODE)
|
||||
|
||||
typedef struct
|
||||
{
|
||||
char* addr;
|
||||
unsigned int size;
|
||||
const char* file;
|
||||
unsigned int line;
|
||||
} mem_data;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
FILE* addr;
|
||||
const char* file_to_open;
|
||||
const char* mode;
|
||||
const char* file;
|
||||
unsigned int line;
|
||||
} file_data;
|
||||
|
||||
static list_admin* memlist = NULL;
|
||||
static list_admin* filelist = NULL;
|
||||
|
||||
static int memory_compare(const void* meminfo, const void* address, size_t size)
|
||||
{
|
||||
mem_data* info = (mem_data*)meminfo;
|
||||
char* addr = (char*)address;
|
||||
return info->addr - addr;
|
||||
}
|
||||
|
||||
static int file_compare(const void* fileinfo, const void* address, size_t size)
|
||||
{
|
||||
file_data* info = (file_data*)fileinfo;
|
||||
FILE* addr = (FILE*)address;
|
||||
return info->addr - addr;
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
invalidate (mem_data* info)
|
||||
{
|
||||
char* user_addr;
|
||||
char* raw_addr;
|
||||
unsigned int size;
|
||||
|
||||
user_addr = info->addr;
|
||||
size = info->size;
|
||||
raw_addr = ADDR (user_addr, -sizeof(int));
|
||||
|
||||
if (!MAGIC_CODE_OK(user_addr, -sizeof(int)) || !MAGIC_CODE_OK(user_addr, size))
|
||||
{
|
||||
fprintf (stderr, "ERROR: addr %p (%s, line %d): out-of-bound access\n", (void*)user_addr, info->file, info->line);
|
||||
}
|
||||
|
||||
memset (raw_addr, 0xff, size + (2 * sizeof(int)));
|
||||
free (raw_addr);
|
||||
}
|
||||
|
||||
/*
|
||||
* replacement of malloc
|
||||
*/
|
||||
extern void*
|
||||
xmalloc (unsigned int size, const char* file, unsigned int line)
|
||||
{
|
||||
char* raw_addr = malloc (size + (2 * sizeof(int)));
|
||||
char* user_addr;
|
||||
mem_data info = {NULL, 0, NULL, 0};
|
||||
|
||||
if (raw_addr == NULL)
|
||||
{
|
||||
fprintf (stderr, "ERROR: malloc failed for %d bytes (%s, line %d)\n", size, file, line);
|
||||
return (NULL);
|
||||
}
|
||||
else
|
||||
{
|
||||
user_addr = ADDR (raw_addr, sizeof (int));
|
||||
SET_MAGIC_CODE (raw_addr, 0);
|
||||
SET_MAGIC_CODE (user_addr, size);
|
||||
|
||||
info.addr = user_addr;
|
||||
info.size = size;
|
||||
info.file = file;
|
||||
info.line = line;
|
||||
list_add_tail(memlist, &info);
|
||||
}
|
||||
return ((void*) user_addr);
|
||||
}
|
||||
|
||||
/*
|
||||
* replacement of free
|
||||
*/
|
||||
extern void
|
||||
xfree (void* addr, const char* filename, int linenr)
|
||||
{
|
||||
char* user_addr = (char*) addr;
|
||||
mem_data* info = NULL;
|
||||
|
||||
/* check if allocated memory is in our list and retrieve its info */
|
||||
int index = list_index_of_special(memlist, addr, memory_compare);
|
||||
info = list_get_element(memlist, index);
|
||||
|
||||
if (info == NULL)
|
||||
{
|
||||
fprintf (stderr, "ERROR: trying to free memory that was not malloc-ed (addr %p) in %s : %d\n", (void*)user_addr, filename, linenr);
|
||||
return;
|
||||
}
|
||||
|
||||
invalidate (info);
|
||||
list_delete_item(memlist, index);
|
||||
}
|
||||
|
||||
static void
|
||||
print_empty_lines(int n)
|
||||
{
|
||||
int i;
|
||||
for (i = 0; i < n; i++)
|
||||
{
|
||||
fprintf(stderr, "\n");
|
||||
}
|
||||
}
|
||||
|
||||
static void set_colour_red(void)
|
||||
{
|
||||
fprintf(stderr, "\033[10;31m");
|
||||
}
|
||||
static void set_colour_gray(void)
|
||||
{
|
||||
fprintf(stderr, "\033[22;37m");
|
||||
}
|
||||
static void
|
||||
print_line(void)
|
||||
{
|
||||
fprintf (stderr, "---------------------------------------------------------\n");
|
||||
}
|
||||
|
||||
static void
|
||||
print_not_good(void)
|
||||
{
|
||||
set_colour_gray();
|
||||
print_line();
|
||||
set_colour_red();
|
||||
fprintf (stderr, " # # ###\n");
|
||||
fprintf (stderr, " ## # #### ##### #### #### #### ##### ###\n");
|
||||
fprintf (stderr, " # # # # # # # # # # # # # # ###\n");
|
||||
fprintf (stderr, " # # # # # # # # # # # # # # \n");
|
||||
fprintf (stderr, " # # # # # # # ### # # # # # # \n");
|
||||
fprintf (stderr, " # ## # # # # # # # # # # # ###\n");
|
||||
fprintf (stderr, " # # #### # #### #### #### ##### ###\n");
|
||||
set_colour_gray();
|
||||
print_line();
|
||||
}
|
||||
|
||||
/*
|
||||
* writes all info of the unallocated memory
|
||||
*/
|
||||
static void
|
||||
resource_detection (void)
|
||||
{
|
||||
time_t now = time (NULL);
|
||||
|
||||
int forgotten_frees = list_get_nr_elements(memlist);
|
||||
int nr_files_open = list_get_nr_elements(filelist);
|
||||
|
||||
if ((forgotten_frees > 0) || (nr_files_open > 0))
|
||||
{
|
||||
print_empty_lines(15);
|
||||
}
|
||||
|
||||
if (forgotten_frees > 0)
|
||||
{
|
||||
mem_data* info = NULL;
|
||||
print_line();
|
||||
fprintf (stderr, "Memory Leak Summary, generated: %s", ctime (&now));
|
||||
print_not_good();
|
||||
set_colour_red();
|
||||
while((info = list_get_element(memlist, 0)) != NULL)
|
||||
{
|
||||
fprintf (stderr, "forgot to free address: %p (%d bytes) that was allocated in: %s on line: %d\n",
|
||||
(void*)info->addr, info->size, info->file, info->line);
|
||||
list_delete_item(memlist, 0);
|
||||
}
|
||||
set_colour_gray();
|
||||
print_line();
|
||||
print_empty_lines(1);
|
||||
}
|
||||
|
||||
if (nr_files_open > 0)
|
||||
{
|
||||
file_data* info = NULL;
|
||||
print_line();
|
||||
fprintf (stderr, "File Management Summary, generated: %s", ctime (&now));
|
||||
print_not_good();
|
||||
set_colour_red();
|
||||
while((info = list_get_element(filelist, 0)) != NULL)
|
||||
{
|
||||
fprintf (stderr, "forgot to close file: %s (ptr %p, mode \"%s\") that was opened from: %s on line: %d\n",
|
||||
info->file_to_open, (void*)(info->addr), info->mode, info->file, info->line);
|
||||
list_delete_item(filelist, 0);
|
||||
}
|
||||
set_colour_gray();
|
||||
print_line();
|
||||
print_empty_lines(1);
|
||||
}
|
||||
if ((forgotten_frees == 0) && (nr_files_open == 0))
|
||||
{
|
||||
printf ("\nResource checks: OK\n\n");
|
||||
}
|
||||
|
||||
destruct_list(&memlist);
|
||||
destruct_list(&filelist);
|
||||
}
|
||||
|
||||
extern FILE*
|
||||
xfopen (const char* file_to_open, const char* mode, const char* filename, int linenr)
|
||||
{
|
||||
file_data info = {0};
|
||||
info.addr = fopen(file_to_open, mode);
|
||||
if (info.addr != NULL)
|
||||
{
|
||||
info.file_to_open = file_to_open;
|
||||
info.mode = mode;
|
||||
info.file = filename;
|
||||
info.line = linenr;
|
||||
list_add_tail(filelist, &info);
|
||||
}
|
||||
return info.addr;
|
||||
}
|
||||
|
||||
extern int
|
||||
xfclose(FILE* fptr, const char* filename, int linenr)
|
||||
{
|
||||
int index = list_index_of_special(filelist, fptr, file_compare);
|
||||
if (index < 0)
|
||||
{
|
||||
fprintf (stderr, "ERROR: trying to close an unopened file in %s on line number %d.\n", filename, linenr);
|
||||
return -1;
|
||||
}
|
||||
list_delete_item(filelist, index);
|
||||
return (fclose (fptr));
|
||||
}
|
||||
|
||||
extern int
|
||||
main (int argc, char* argv[])
|
||||
{
|
||||
atexit (resource_detection);
|
||||
memlist = construct_list(sizeof(mem_data));
|
||||
filelist = construct_list(sizeof(file_data));
|
||||
|
||||
return (xmain (argc, argv));
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
#ifndef RESOURCE_DETECTOR_H
|
||||
#define RESOURCE_DETECTOR_H
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#define main xmain
|
||||
#define malloc(size) xmalloc ((size), (__FILE__), (__LINE__))
|
||||
#define free(addr) xfree ((addr), __FILE__, __LINE__)
|
||||
#define fopen(name,mode) xfopen ((name),(mode), __FILE__, __LINE__)
|
||||
#define fclose(fptr) xfclose ((fptr), __FILE__, __LINE__)
|
||||
|
||||
extern int xmain(int argc, char* argv[]);
|
||||
extern void* xmalloc(unsigned int size, const char* file, unsigned int line);
|
||||
extern void xfree(void* addr, const char* filename, int linenr);
|
||||
extern FILE* xfopen(const char* file_to_open, const char* mode, const char* filename, int linenr);
|
||||
extern int xfclose(FILE* fptr, const char* filename, int linenr);
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,28 @@
|
||||
UNITY_FOLDER=../Unity
|
||||
TEST_INC_DIRS=$(INC_DIRS) -I$(UNITY_FOLDER)
|
||||
|
||||
TEST_FILES=$(UNITY_FOLDER)/unity.c \
|
||||
list_test.c \
|
||||
list.c
|
||||
|
||||
HEADER_FILES=*.h
|
||||
|
||||
TEST = list_test
|
||||
|
||||
CC=gcc
|
||||
|
||||
SYMBOLS=-Wall -Werror -pedantic -O0 -ggdb -std=c99
|
||||
TEST_SYMBOLS=$(SYMBOLS) -DTEST
|
||||
|
||||
.PHONY: clean test
|
||||
|
||||
all: $(TEST)
|
||||
|
||||
$(TEST): Makefile $(TEST_FILES) $(HEADER_FILES)
|
||||
$(CC) $(TEST_INC_DIRS) $(TEST_SYMBOLS) $(TEST_FILES) -o $(TEST)
|
||||
|
||||
clean:
|
||||
rm -f list $(TEST)
|
||||
|
||||
test: $(TEST)
|
||||
@valgrind ./$(TEST)
|
||||
@@ -0,0 +1,300 @@
|
||||
#include <string.h> /* for memcmp */
|
||||
|
||||
#include "list.h"
|
||||
#include "unity.h"
|
||||
|
||||
// I rather dislike keeping line numbers updated, so I made my own macro to ditch the line number
|
||||
#define MY_RUN_TEST(func) RUN_TEST(func, 0)
|
||||
|
||||
static list_admin* mylist = NULL;
|
||||
typedef struct
|
||||
{
|
||||
int i;
|
||||
int j;
|
||||
} test_struct;
|
||||
|
||||
// compare function that returns 0 if test_struct.i matches, it ignores .j
|
||||
static int compare_test_func(const void* p1, const void* p2, size_t size)
|
||||
{
|
||||
size = size; // to prevent warnings
|
||||
const test_struct* data1 = (const test_struct*)p1;
|
||||
const test_struct* data2 = (const test_struct*)p2;
|
||||
return data1->i - data2->i;
|
||||
}
|
||||
// check n items in list against verify_data
|
||||
// IMPORTANT: this function must check using list_get_element,
|
||||
// else the test for that function is no longer useful
|
||||
static void check_n_list_elements_ok(list_admin* admin, int nr_items, const test_struct* verify_data)
|
||||
{
|
||||
for(int i = 0; i < nr_items; i++)
|
||||
{
|
||||
test_struct* ptr = list_get_element(admin, i);
|
||||
TEST_ASSERT_NOT_NULL(ptr);
|
||||
TEST_ASSERT_EQUAL(0, memcmp(verify_data+i, ptr, sizeof(*ptr)));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void setUp(void)
|
||||
{
|
||||
// This is run before EACH test
|
||||
mylist = construct_list(sizeof(test_struct));
|
||||
TEST_ASSERT_NOT_NULL(mylist);
|
||||
}
|
||||
|
||||
void tearDown(void)
|
||||
{
|
||||
// This is run after EACH test
|
||||
destruct_list(&mylist);
|
||||
TEST_ASSERT_NULL(mylist);
|
||||
}
|
||||
|
||||
static void test_ConstructList(void)
|
||||
{
|
||||
TEST_ASSERT_NULL(mylist->head);
|
||||
TEST_ASSERT_EQUAL(sizeof(test_struct), mylist->element_size);
|
||||
TEST_ASSERT_EQUAL(0, mylist->nr_elements);
|
||||
}
|
||||
|
||||
static void test_NrElements_parameters(void)
|
||||
{
|
||||
TEST_ASSERT_EQUAL(-1, list_get_nr_elements(NULL));
|
||||
}
|
||||
|
||||
static void test_AddData_parameters(void)
|
||||
{
|
||||
TEST_ASSERT_EQUAL(-1, list_add_tail(mylist, NULL));
|
||||
TEST_ASSERT_EQUAL(-1, list_add_tail(NULL, mylist));
|
||||
}
|
||||
|
||||
static void test_AddData(void)
|
||||
{
|
||||
test_struct data = {3, 4};
|
||||
TEST_ASSERT_EQUAL(0, list_add_tail(mylist, &data));
|
||||
|
||||
TEST_ASSERT_NOT_NULL(mylist->head);
|
||||
TEST_ASSERT_EQUAL(1, list_get_nr_elements(mylist));
|
||||
list_head* head = mylist->head;
|
||||
test_struct* element = (test_struct*)(head+1);
|
||||
TEST_ASSERT_EQUAL(data.i, element->i);
|
||||
TEST_ASSERT_EQUAL(data.j, element->j);
|
||||
}
|
||||
|
||||
static void test_Add2PiecesOfData(void)
|
||||
{
|
||||
test_struct data1 = {8, 9};
|
||||
test_struct data2 = {-3, -4};
|
||||
TEST_ASSERT_EQUAL(0, list_add_tail(mylist, &data1));
|
||||
TEST_ASSERT_EQUAL(0, list_add_tail(mylist, &data2));
|
||||
|
||||
TEST_ASSERT_NOT_NULL(mylist->head);
|
||||
TEST_ASSERT_NOT_NULL(mylist->head->next);
|
||||
TEST_ASSERT_EQUAL(2, list_get_nr_elements(mylist));
|
||||
list_head* head = mylist->head->next;
|
||||
test_struct* element = (test_struct*)(head+1);
|
||||
TEST_ASSERT_EQUAL(data2.i, element->i);
|
||||
TEST_ASSERT_EQUAL(data2.j, element->j);
|
||||
}
|
||||
|
||||
static void test_GetElement_parameters(void)
|
||||
{
|
||||
TEST_ASSERT_NULL(list_get_element(NULL, 0));
|
||||
}
|
||||
|
||||
static void test_GetElement(void)
|
||||
{
|
||||
const test_struct data[] = {{8, 9}, {-3, -4}, {21, 56}, {0, 0}};
|
||||
const int nr_elements = sizeof(data)/sizeof(data[0]);
|
||||
|
||||
for(int i = 0; i < nr_elements; i++)
|
||||
{
|
||||
TEST_ASSERT_EQUAL(0, list_add_tail(mylist, &(data[i])));
|
||||
}
|
||||
|
||||
check_n_list_elements_ok(mylist, nr_elements, data); // checks using list_get_element
|
||||
|
||||
TEST_ASSERT_NULL(list_get_element(mylist, nr_elements));
|
||||
TEST_ASSERT_NULL(list_get_element(mylist, -1));
|
||||
}
|
||||
|
||||
static void test_GetLast_parameters(void)
|
||||
{
|
||||
TEST_ASSERT_NULL(list_get_last(NULL));
|
||||
}
|
||||
|
||||
static void test_GetLast(void)
|
||||
{
|
||||
const test_struct data[] = {{8, 9}, {-3, -4}, {21, 56}, {0, 0}};
|
||||
const int nr_elements = sizeof(data)/sizeof(data[0]);
|
||||
|
||||
TEST_ASSERT_NULL(list_get_last(mylist));
|
||||
for(int i = 0; i < nr_elements; i++)
|
||||
{
|
||||
TEST_ASSERT_EQUAL(0, list_add_tail(mylist, &(data[i])));
|
||||
test_struct* ptr = list_get_last(mylist);
|
||||
TEST_ASSERT_NOT_NULL(ptr);
|
||||
TEST_ASSERT_EQUAL(0, memcmp(&(data[i]), ptr, sizeof(*ptr)));
|
||||
}
|
||||
}
|
||||
|
||||
static void test_IndexOf_parameters(void)
|
||||
{
|
||||
TEST_ASSERT_EQUAL(-1, list_index_of(mylist, NULL));
|
||||
TEST_ASSERT_EQUAL(-1, list_index_of(NULL, mylist));
|
||||
}
|
||||
|
||||
static void test_IndexOf(void)
|
||||
{
|
||||
const test_struct real_data[] = {{8, 9}, {-3, -4}, {21, 56}};
|
||||
const int nr_real_elements = sizeof(real_data)/sizeof(real_data[0]);
|
||||
const test_struct false_data[] = {{-3, 9}, {8, 56}, {21, -4}, {0, 0}};
|
||||
const int nr_false_elements = sizeof(false_data)/sizeof(false_data[0]);
|
||||
for(int i = 0; i < nr_real_elements; i++)
|
||||
{
|
||||
TEST_ASSERT_EQUAL(0, list_add_tail(mylist, &(real_data[i])));
|
||||
}
|
||||
|
||||
for(int i = 0; i < nr_real_elements; i++)
|
||||
{
|
||||
TEST_ASSERT_EQUAL(i, list_index_of(mylist, &(real_data[i])));
|
||||
}
|
||||
for(int i = 0; i < nr_false_elements; i++)
|
||||
{
|
||||
TEST_ASSERT_EQUAL(-1, list_index_of(mylist, &(false_data[i])));
|
||||
}
|
||||
}
|
||||
|
||||
static void test_IndexOfSpecial_parameters(void)
|
||||
{
|
||||
TEST_ASSERT_EQUAL(-1, list_index_of_special(mylist, NULL, compare_test_func));
|
||||
TEST_ASSERT_EQUAL(-1, list_index_of_special(NULL, mylist, compare_test_func));
|
||||
TEST_ASSERT_EQUAL(-1, list_index_of_special(mylist, mylist, NULL));
|
||||
}
|
||||
|
||||
static void test_IndexOfSpecial(void)
|
||||
{
|
||||
const test_struct data[] = {{8, 9}, {-3, -4}, {21, 56}}; // data in list
|
||||
const test_struct real_data[] = {{8, -4}, {-3, 56}, {21, 9}}; // data to search for (i equals)
|
||||
const int nr_real_elements = sizeof(real_data)/sizeof(real_data[0]);
|
||||
const test_struct false_data[] = {{-2, 9}, {9, -4}, {22, 56}, {0, 0}}; // data that doesn't exist
|
||||
const int nr_false_elements = sizeof(false_data)/sizeof(false_data[0]);
|
||||
|
||||
// first make sure our compare function works
|
||||
for(int i = 0; i < nr_real_elements; i++)
|
||||
{
|
||||
TEST_ASSERT_EQUAL(0, compare_test_func(&(data[i]), &(real_data[i]), 0));
|
||||
for (int j = 0; j < nr_false_elements; j++)
|
||||
{
|
||||
TEST_ASSERT_NOT_EQUAL(0, compare_test_func(&(data[i]), &(false_data[j]), 0))
|
||||
}
|
||||
}
|
||||
|
||||
for(int i = 0; i < nr_real_elements; i++)
|
||||
{
|
||||
TEST_ASSERT_EQUAL(0, list_add_tail(mylist, &(data[i])));
|
||||
}
|
||||
|
||||
for(int i = 0; i < nr_real_elements; i++)
|
||||
{
|
||||
TEST_ASSERT_EQUAL(i, list_index_of_special(mylist, &(real_data[i]), compare_test_func));
|
||||
}
|
||||
for(int i = 0; i < nr_false_elements; i++)
|
||||
{
|
||||
TEST_ASSERT_EQUAL(-1, list_index_of_special(mylist, &(false_data[i]), compare_test_func));
|
||||
}
|
||||
}
|
||||
|
||||
static void test_DeleteItem_parameters(void)
|
||||
{
|
||||
TEST_ASSERT_EQUAL(-1, list_delete_item(NULL, 0));
|
||||
TEST_ASSERT_EQUAL(-1, list_delete_item(mylist, -1));
|
||||
}
|
||||
|
||||
static void test_DeleteItem(void)
|
||||
{
|
||||
const test_struct data[] = {{8, 9}, {-3, -4}, {21, 56}, {0, 0}, {12, 12345}};
|
||||
int nr_elements = sizeof(data)/sizeof(data[0]);
|
||||
const test_struct data_noFirst[] = {{-3, -4}, {21, 56}, {0, 0}, {12, 12345}};
|
||||
const test_struct data_noLast[] = {{-3, -4}, {21, 56}, {0, 0}};
|
||||
const test_struct data_noMiddle[] = {{-3, -4}, {0, 0}};
|
||||
|
||||
TEST_ASSERT_EQUAL(-1, list_delete_item(mylist, 0));
|
||||
for(int i = 0; i < nr_elements; i++)
|
||||
{
|
||||
TEST_ASSERT_EQUAL(0, list_add_tail(mylist, &(data[i])));
|
||||
}
|
||||
|
||||
TEST_ASSERT_EQUAL(0, list_delete_item(mylist, 0));
|
||||
nr_elements--;
|
||||
TEST_ASSERT_EQUAL(nr_elements, list_get_nr_elements(mylist));
|
||||
|
||||
check_n_list_elements_ok(mylist, nr_elements, data_noFirst);
|
||||
|
||||
TEST_ASSERT_EQUAL(0, list_delete_item(mylist, nr_elements-1));
|
||||
nr_elements--;
|
||||
TEST_ASSERT_EQUAL(nr_elements, list_get_nr_elements(mylist));
|
||||
|
||||
check_n_list_elements_ok(mylist, nr_elements, data_noLast);
|
||||
|
||||
TEST_ASSERT_EQUAL(0, list_delete_item(mylist, 1));
|
||||
nr_elements--;
|
||||
TEST_ASSERT_EQUAL(nr_elements, list_get_nr_elements(mylist));
|
||||
|
||||
check_n_list_elements_ok(mylist, nr_elements, data_noMiddle);
|
||||
}
|
||||
|
||||
static void test_DeleteLast_parameters(void)
|
||||
{
|
||||
TEST_ASSERT_EQUAL(-1, list_delete_last(NULL));
|
||||
}
|
||||
|
||||
static void test_DeleteLast(void)
|
||||
{
|
||||
const test_struct data[] = {{8, 9}, {-3, -4}, {21, 56}, {0, 0}, {12, 12345}};
|
||||
int nr_elements = sizeof(data)/sizeof(data[0]);
|
||||
|
||||
TEST_ASSERT_EQUAL(-1, list_delete_last(mylist));
|
||||
for(int i = 0; i < nr_elements; i++)
|
||||
{
|
||||
TEST_ASSERT_EQUAL(0, list_add_tail(mylist, &(data[i])));
|
||||
}
|
||||
|
||||
for (int i = nr_elements-1; i >= 0; i--)
|
||||
{
|
||||
TEST_ASSERT_EQUAL(0, list_delete_last(mylist));
|
||||
TEST_ASSERT_EQUAL(i, list_get_nr_elements(mylist));
|
||||
check_n_list_elements_ok(mylist, i, data);
|
||||
}
|
||||
|
||||
TEST_ASSERT_NULL(mylist->head);
|
||||
TEST_ASSERT_EQUAL(0, list_get_nr_elements(mylist));
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
UnityBegin();
|
||||
|
||||
MY_RUN_TEST(test_ConstructList);
|
||||
MY_RUN_TEST(test_NrElements_parameters);
|
||||
MY_RUN_TEST(test_AddData_parameters);
|
||||
MY_RUN_TEST(test_AddData);
|
||||
MY_RUN_TEST(test_Add2PiecesOfData);
|
||||
MY_RUN_TEST(test_GetElement_parameters);
|
||||
MY_RUN_TEST(test_GetElement);
|
||||
MY_RUN_TEST(test_GetLast_parameters);
|
||||
MY_RUN_TEST(test_GetLast);
|
||||
MY_RUN_TEST(test_IndexOf_parameters);
|
||||
MY_RUN_TEST(test_IndexOf);
|
||||
MY_RUN_TEST(test_IndexOfSpecial_parameters);
|
||||
MY_RUN_TEST(test_IndexOfSpecial);
|
||||
MY_RUN_TEST(test_DeleteItem_parameters);
|
||||
MY_RUN_TEST(test_DeleteItem);
|
||||
MY_RUN_TEST(test_DeleteLast_parameters);
|
||||
MY_RUN_TEST(test_DeleteLast);
|
||||
// MY_RUN_TEST();
|
||||
// MY_RUN_TEST();
|
||||
// MY_RUN_TEST();
|
||||
// MY_RUN_TEST();
|
||||
|
||||
return UnityEnd();
|
||||
}
|
||||
BIN
C/C(extra) ExtraAssignments/Stegano/SteganoAssignment.doc
Normal file
BIN
C/C(extra) ExtraAssignments/Stegano/SteganoAssignment.doc
Normal file
Binary file not shown.
102
C/C(extra) ExtraAssignments/Stegano/TextFontys.txt
Normal file
102
C/C(extra) ExtraAssignments/Stegano/TextFontys.txt
Normal file
@@ -0,0 +1,102 @@
|
||||
*** Eindhoven ***
|
||||
|
||||
De Technische Universiteit Eindhoven en Fontys Hogescholen trekken veel
|
||||
studenten naar Eindhoven. In de digitale stad Eindhoven en
|
||||
Eindhoven.beginthier.nl vind je een bundeling van informatie over Eindhoven.
|
||||
Je mag Eindhoven een echte studentenstad noemen. Studentvoorzieningen zijn
|
||||
er op allerlei gebied. Hieronder vind je een aantal mogelijkheden:
|
||||
|
||||
|
||||
Introfestival
|
||||
=============
|
||||
Om je kennis te laten maken met het studentenleven in Eindhoven
|
||||
worden al jaren de HBO Introductiedagen (HID) georganiseerd: een
|
||||
bruisend festival met veel muziek. Tijdens deze drie dwaze dagen leer
|
||||
je de studentenverenigingen kennen, je gaat langs bij veel kroegen in
|
||||
de stad en je ontmoet een heleboel medestudenten. Je ontvangt automatisch
|
||||
bericht over de HID als je je hebt aangemeld voor een opleiding.
|
||||
|
||||
|
||||
FEID (Fontys Eindhoven Introductie Dag) is de algemene introductiedag
|
||||
van Fontys in Eindhoven waar alle studenten die gaan studeren aan een
|
||||
van de opleidingen die Fontys aanbiedt, aan mee doen.
|
||||
|
||||
|
||||
Gezelligheid
|
||||
------------
|
||||
Een geslaagd studentenleven kan je in Eindhoven op verschillende manier
|
||||
bereiken. Op de donderdagavonden in de stad, bijvoorbeeld op uitgaansgebied
|
||||
Stratumseind, bij de cultuur- en sportverenigingen, enz. De drie Eindhovense
|
||||
studenten-gezelligheidsverenigingen vervullen een sleutelrol in dit geheel.
|
||||
Ze hebben alledrie een eigen identiteit en unieke sfeer: het Eindhovense
|
||||
Studentencorps, SSRE en Demos.
|
||||
|
||||
|
||||
Sport
|
||||
+++++
|
||||
|
||||
Als Fontysstudent kun je gebruik maken van alle accommodaties van het
|
||||
TU-Sportcentrum op het terrein van de Technische Universiteit Eindhoven.
|
||||
Als je bent ingeschreven voor een Fontysopleiding ontvang je daarover
|
||||
automatisch informatie.
|
||||
|
||||
De Eindhovense Studenten Sport Federatie (de ESSF) is een overkoepelend
|
||||
orgaan en belangenbehartiger van alle studenten sportverenigingen en
|
||||
alle sportkaarthouders in Eindhoven. Heb je vragen over de sportkaart
|
||||
en/of het sporten, kijk dan op de website van de ESSF.
|
||||
|
||||
|
||||
Wat houdt Technische Informatica in?
|
||||
====================================
|
||||
|
||||
Binnen het vakgebied Technische Informatica ben je samen met anderen bezig
|
||||
om computerprogrammatuur te maken in een technische omgeving. Je doorloopt
|
||||
in een aantal projecten en modulen het totale ontwikkeltraject van
|
||||
softwaresystemen: van het inventariseren van wensen van toekomstige gebruikers,
|
||||
via het beschrijven en realiseren van een ontwerp tot het testen en implementeren
|
||||
in een werkomgeving. De opleiding besteedt uitgebreid aandacht aan embedded
|
||||
systemen: software die in apparaten wordt ingebouwd. Denk maar eens aan al
|
||||
die programmatuur in kopieerapparaten, liften, wasmachines en mobiele
|
||||
telefoons.
|
||||
|
||||
|
||||
Een ander aandachtsgebied is industri<72>le automatisering. Bij industri<72>le
|
||||
automatisering kun je denken aan robots. Andere voorbeelden zijn:
|
||||
verkeerssystemen op snelwegen en in tunnels, parkeergarages met automatische
|
||||
betalingen, massafabricage in de auto- en elektronica-industrie, procesbesturing
|
||||
via internet,en productinspectie met camera's en beeldbewerking. Omdat je als
|
||||
ict<EFBFBD>ers, dus ook als technisch informaticus, met en voor mensen werkt, is er
|
||||
ook aandacht voor communicatieve en sociale vaardigheden.
|
||||
|
||||
|
||||
Learning Community
|
||||
==================
|
||||
|
||||
Fontys wil een open organisatie zijn, waarin geleerd wordt in wisselwerking
|
||||
met de omgeving. Leren gebeurt vooral met anderen en in steeds wisselende
|
||||
groepen en situaties. Met haar studenten wil Fontys een hechte en langdurige
|
||||
relatie aangaan. Ontwikkeling, competenties, vaardigheden en eigen keuzes
|
||||
staan daarbij voorop.
|
||||
|
||||
Elke student formuleert eigen leervragen, be<62>nvloedt de eigen leerroute en
|
||||
reflecteert kritisch op het eigen leerproces. Binnen de instituten worden
|
||||
studenten praktijkgericht opgeleid tot professional.
|
||||
|
||||
|
||||
Organisatie
|
||||
===========
|
||||
|
||||
Fontys telt zo'n 33.000 studenten en 3.500 personeelsleden.
|
||||
|
||||
De opleidingen en diensten van Fontys Hogescholen worden verzorgd door 35
|
||||
hogescholen (met eigen directies). De leiding van Fontys Hogescholen berust
|
||||
bij de Raad van Bestuur, die ondersteund wordt door een Bestuursstaf. Zowel
|
||||
de Raad van Bestuur als de hogescholen maken voor diverse diensten gebruik
|
||||
van het Facilitair Bedrijf, dat afdelingen herbergt als ICT-Services,
|
||||
Studentenvoorzieningen, Administratieve en Huishoudelijke functies.
|
||||
|
||||
|
||||
|
||||
Bron: http://www.fontys.nl
|
||||
|
||||
-- einde --
|
||||
841
C/C(extra) ExtraAssignments/Stegano/Unity/unity.c
Normal file
841
C/C(extra) ExtraAssignments/Stegano/Unity/unity.c
Normal file
@@ -0,0 +1,841 @@
|
||||
/* ==========================================
|
||||
Unity Project - A Test Framework for C
|
||||
Copyright (c) 2007 Mike Karlesky, Mark VanderVoord, Greg Williams
|
||||
[Released under MIT License. Please refer to license.txt for details]
|
||||
========================================== */
|
||||
|
||||
#include "unity.h"
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#define UNITY_FAIL_AND_BAIL { Unity.CurrentTestFailed = 1; UNITY_OUTPUT_CHAR('\n'); longjmp(Unity.AbortFrame, 1); }
|
||||
#define UNITY_IGNORE_AND_BAIL { Unity.CurrentTestIgnored = 1; UNITY_OUTPUT_CHAR('\n'); longjmp(Unity.AbortFrame, 1); }
|
||||
/// return prematurely if we are already in failure or ignore state
|
||||
#define UNITY_SKIP_EXECUTION { if ((Unity.CurrentTestFailed != 0) || (Unity.CurrentTestIgnored != 0)) {return;} }
|
||||
#define UNITY_PRINT_EOL { UNITY_OUTPUT_CHAR('\n'); }
|
||||
|
||||
struct _Unity Unity = { 0 };
|
||||
|
||||
const char* UnityStrNull = "NULL";
|
||||
const char* UnityStrSpacer = ". ";
|
||||
const char* UnityStrExpected = " Expected ";
|
||||
const char* UnityStrWas = " Was ";
|
||||
const char* UnityStrTo = " To ";
|
||||
const char* UnityStrElement = " Element ";
|
||||
const char* UnityStrMemory = " Memory Mismatch";
|
||||
const char* UnityStrDelta = " Values Not Within Delta ";
|
||||
const char* UnityStrPointless= " You Asked Me To Compare Nothing, Which Was Pointless.";
|
||||
const char* UnityStrNullPointerForExpected= " Expected pointer to be NULL";
|
||||
const char* UnityStrNullPointerForActual = " Actual pointer was NULL";
|
||||
|
||||
//-----------------------------------------------
|
||||
// Pretty Printers & Test Result Output Handlers
|
||||
//-----------------------------------------------
|
||||
|
||||
void UnityPrint(const char* string)
|
||||
{
|
||||
const char* pch = string;
|
||||
|
||||
if (pch != NULL)
|
||||
{
|
||||
while (*pch)
|
||||
{
|
||||
// printable characters plus CR & LF are printed
|
||||
if ((*pch <= 126) && (*pch >= 32))
|
||||
{
|
||||
UNITY_OUTPUT_CHAR(*pch);
|
||||
}
|
||||
//write escaped carriage returns
|
||||
else if (*pch == 13)
|
||||
{
|
||||
UNITY_OUTPUT_CHAR('\\');
|
||||
UNITY_OUTPUT_CHAR('r');
|
||||
}
|
||||
//write escaped line feeds
|
||||
else if (*pch == 10)
|
||||
{
|
||||
UNITY_OUTPUT_CHAR('\\');
|
||||
UNITY_OUTPUT_CHAR('n');
|
||||
}
|
||||
// unprintable characters are shown as codes
|
||||
else
|
||||
{
|
||||
UNITY_OUTPUT_CHAR('\\');
|
||||
UnityPrintNumberHex((_U_SINT)*pch, 2);
|
||||
}
|
||||
pch++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------
|
||||
void UnityPrintNumberByStyle(const _U_SINT number, const UNITY_DISPLAY_STYLE_T style)
|
||||
{
|
||||
if ((style & UNITY_DISPLAY_RANGE_INT) == UNITY_DISPLAY_RANGE_INT)
|
||||
{
|
||||
UnityPrintNumber(number);
|
||||
}
|
||||
else if ((style & UNITY_DISPLAY_RANGE_UINT) == UNITY_DISPLAY_RANGE_UINT)
|
||||
{
|
||||
UnityPrintNumberUnsigned((_U_UINT)number);
|
||||
}
|
||||
else
|
||||
{
|
||||
UnityPrintNumberHex((_U_UINT)number, (style & 0x000F) << 1);
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------
|
||||
/// basically do an itoa using as little ram as possible
|
||||
void UnityPrintNumber(const _U_SINT number_to_print)
|
||||
{
|
||||
_U_SINT divisor = 1;
|
||||
_U_SINT next_divisor;
|
||||
_U_SINT number = number_to_print;
|
||||
|
||||
if (number < 0)
|
||||
{
|
||||
UNITY_OUTPUT_CHAR('-');
|
||||
number = -number;
|
||||
}
|
||||
|
||||
// figure out initial divisor
|
||||
while (number / divisor > 9)
|
||||
{
|
||||
next_divisor = divisor * 10;
|
||||
if (next_divisor > divisor)
|
||||
divisor = next_divisor;
|
||||
else
|
||||
break;
|
||||
}
|
||||
|
||||
// now mod and print, then divide divisor
|
||||
do
|
||||
{
|
||||
UNITY_OUTPUT_CHAR((char)('0' + (number / divisor % 10)));
|
||||
divisor /= 10;
|
||||
}
|
||||
while (divisor > 0);
|
||||
}
|
||||
|
||||
//-----------------------------------------------
|
||||
/// basically do an itoa using as little ram as possible
|
||||
void UnityPrintNumberUnsigned(const _U_UINT number)
|
||||
{
|
||||
_U_UINT divisor = 1;
|
||||
_U_UINT next_divisor;
|
||||
|
||||
// figure out initial divisor
|
||||
while (number / divisor > 9)
|
||||
{
|
||||
next_divisor = divisor * 10;
|
||||
if (next_divisor > divisor)
|
||||
divisor = next_divisor;
|
||||
else
|
||||
break;
|
||||
}
|
||||
|
||||
// now mod and print, then divide divisor
|
||||
do
|
||||
{
|
||||
UNITY_OUTPUT_CHAR((char)('0' + (number / divisor % 10)));
|
||||
divisor /= 10;
|
||||
}
|
||||
while (divisor > 0);
|
||||
}
|
||||
|
||||
//-----------------------------------------------
|
||||
void UnityPrintNumberHex(const _U_UINT number, const char nibbles_to_print)
|
||||
{
|
||||
_U_UINT nibble;
|
||||
char nibbles = nibbles_to_print;
|
||||
UNITY_OUTPUT_CHAR('0');
|
||||
UNITY_OUTPUT_CHAR('x');
|
||||
|
||||
while (nibbles > 0)
|
||||
{
|
||||
nibble = (number >> (--nibbles << 2)) & 0x0000000F;
|
||||
if (nibble <= 9)
|
||||
{
|
||||
UNITY_OUTPUT_CHAR((char)('0' + nibble));
|
||||
}
|
||||
else
|
||||
{
|
||||
UNITY_OUTPUT_CHAR((char)('A' - 10 + nibble));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------
|
||||
void UnityPrintMask(const _U_UINT mask, const _U_UINT number)
|
||||
{
|
||||
_U_UINT current_bit = (_U_UINT)1 << (UNITY_INT_WIDTH - 1);
|
||||
_US32 i;
|
||||
|
||||
for (i = 0; i < UNITY_INT_WIDTH; i++)
|
||||
{
|
||||
if (current_bit & mask)
|
||||
{
|
||||
if (current_bit & number)
|
||||
{
|
||||
UNITY_OUTPUT_CHAR('1');
|
||||
}
|
||||
else
|
||||
{
|
||||
UNITY_OUTPUT_CHAR('0');
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
UNITY_OUTPUT_CHAR('X');
|
||||
}
|
||||
current_bit = current_bit >> 1;
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------
|
||||
#ifdef UNITY_FLOAT_VERBOSE
|
||||
void UnityPrintFloat(_UF number)
|
||||
{
|
||||
char TempBuffer[32];
|
||||
sprintf(TempBuffer, "%.6f", number);
|
||||
UnityPrint(TempBuffer);
|
||||
}
|
||||
#endif
|
||||
|
||||
//-----------------------------------------------
|
||||
void UnityTestResultsBegin(const char* file, const UNITY_LINE_TYPE line)
|
||||
{
|
||||
UnityPrint(file);
|
||||
UNITY_OUTPUT_CHAR(':');
|
||||
UnityPrintNumber(line);
|
||||
UNITY_OUTPUT_CHAR(':');
|
||||
UnityPrint(Unity.CurrentTestName);
|
||||
UNITY_OUTPUT_CHAR(':');
|
||||
}
|
||||
|
||||
//-----------------------------------------------
|
||||
void UnityTestResultsFailBegin(const UNITY_LINE_TYPE line)
|
||||
{
|
||||
UnityTestResultsBegin(Unity.TestFile, line);
|
||||
UnityPrint("FAIL:");
|
||||
}
|
||||
|
||||
//-----------------------------------------------
|
||||
void UnityConcludeTest(void)
|
||||
{
|
||||
if (Unity.CurrentTestIgnored)
|
||||
{
|
||||
Unity.TestIgnores++;
|
||||
}
|
||||
else if (!Unity.CurrentTestFailed)
|
||||
{
|
||||
UnityTestResultsBegin(Unity.TestFile, Unity.CurrentTestLineNumber);
|
||||
UnityPrint("PASS");
|
||||
UNITY_PRINT_EOL;
|
||||
}
|
||||
else
|
||||
{
|
||||
Unity.TestFailures++;
|
||||
}
|
||||
|
||||
Unity.CurrentTestFailed = 0;
|
||||
Unity.CurrentTestIgnored = 0;
|
||||
}
|
||||
|
||||
//-----------------------------------------------
|
||||
void UnityAddMsgIfSpecified(const char* msg)
|
||||
{
|
||||
if (msg)
|
||||
{
|
||||
UnityPrint(UnityStrSpacer);
|
||||
UnityPrint(msg);
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------
|
||||
void UnityPrintExpectedAndActualStrings(const char* expected, const char* actual)
|
||||
{
|
||||
UnityPrint(UnityStrExpected);
|
||||
if (expected != NULL)
|
||||
{
|
||||
UNITY_OUTPUT_CHAR('\'');
|
||||
UnityPrint(expected);
|
||||
UNITY_OUTPUT_CHAR('\'');
|
||||
}
|
||||
else
|
||||
{
|
||||
UnityPrint(UnityStrNull);
|
||||
}
|
||||
UnityPrint(UnityStrWas);
|
||||
if (actual != NULL)
|
||||
{
|
||||
UNITY_OUTPUT_CHAR('\'');
|
||||
UnityPrint(actual);
|
||||
UNITY_OUTPUT_CHAR('\'');
|
||||
}
|
||||
else
|
||||
{
|
||||
UnityPrint(UnityStrNull);
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------
|
||||
// Assertion & Control Helpers
|
||||
//-----------------------------------------------
|
||||
|
||||
int UnityCheckArraysForNull(const void* expected, const void* actual, const UNITY_LINE_TYPE lineNumber, const char* msg)
|
||||
{
|
||||
//return true if they are both NULL
|
||||
if ((expected == NULL) && (actual == NULL))
|
||||
return 1;
|
||||
|
||||
//throw error if just expected is NULL
|
||||
if (expected == NULL)
|
||||
{
|
||||
UnityTestResultsFailBegin(lineNumber);
|
||||
UnityPrint(UnityStrNullPointerForExpected);
|
||||
UnityAddMsgIfSpecified(msg);
|
||||
UNITY_FAIL_AND_BAIL;
|
||||
}
|
||||
|
||||
//throw error if just actual is NULL
|
||||
if (actual == NULL)
|
||||
{
|
||||
UnityTestResultsFailBegin(lineNumber);
|
||||
UnityPrint(UnityStrNullPointerForActual);
|
||||
UnityAddMsgIfSpecified(msg);
|
||||
UNITY_FAIL_AND_BAIL;
|
||||
}
|
||||
|
||||
//return false if neither is NULL
|
||||
return 0;
|
||||
}
|
||||
|
||||
//-----------------------------------------------
|
||||
// Assertion Functions
|
||||
//-----------------------------------------------
|
||||
|
||||
void UnityAssertBits(const _U_SINT mask,
|
||||
const _U_SINT expected,
|
||||
const _U_SINT actual,
|
||||
const char* msg,
|
||||
const UNITY_LINE_TYPE lineNumber)
|
||||
{
|
||||
UNITY_SKIP_EXECUTION;
|
||||
|
||||
if ((mask & expected) != (mask & actual))
|
||||
{
|
||||
UnityTestResultsFailBegin(lineNumber);
|
||||
UnityPrint(UnityStrExpected);
|
||||
UnityPrintMask(mask, expected);
|
||||
UnityPrint(UnityStrWas);
|
||||
UnityPrintMask(mask, actual);
|
||||
UnityAddMsgIfSpecified(msg);
|
||||
UNITY_FAIL_AND_BAIL;
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------
|
||||
void UnityAssertEqualNumber(const _U_SINT expected,
|
||||
const _U_SINT actual,
|
||||
const char* msg,
|
||||
const UNITY_LINE_TYPE lineNumber,
|
||||
const UNITY_DISPLAY_STYLE_T style)
|
||||
{
|
||||
UNITY_SKIP_EXECUTION;
|
||||
|
||||
if (expected != actual)
|
||||
{
|
||||
UnityTestResultsFailBegin(lineNumber);
|
||||
UnityPrint(UnityStrExpected);
|
||||
UnityPrintNumberByStyle(expected, style);
|
||||
UnityPrint(UnityStrWas);
|
||||
UnityPrintNumberByStyle(actual, style);
|
||||
UnityAddMsgIfSpecified(msg);
|
||||
UNITY_FAIL_AND_BAIL;
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------
|
||||
void UnityAssertEqualIntArray(const _U_SINT* expected,
|
||||
const _U_SINT* actual,
|
||||
const _UU32 num_elements,
|
||||
const char* msg,
|
||||
const UNITY_LINE_TYPE lineNumber,
|
||||
const UNITY_DISPLAY_STYLE_T style)
|
||||
{
|
||||
_UU32 elements = num_elements;
|
||||
const _US8* ptr_exp = (_US8*)expected;
|
||||
const _US8* ptr_act = (_US8*)actual;
|
||||
|
||||
UNITY_SKIP_EXECUTION;
|
||||
|
||||
if (elements == 0)
|
||||
{
|
||||
UnityTestResultsFailBegin(lineNumber);
|
||||
UnityPrint(UnityStrPointless);
|
||||
UnityAddMsgIfSpecified(msg);
|
||||
UNITY_FAIL_AND_BAIL;
|
||||
}
|
||||
|
||||
if (UnityCheckArraysForNull((void*)expected, (void*)actual, lineNumber, msg) == 1)
|
||||
return;
|
||||
|
||||
switch(style)
|
||||
{
|
||||
case UNITY_DISPLAY_STYLE_HEX8:
|
||||
case UNITY_DISPLAY_STYLE_INT8:
|
||||
case UNITY_DISPLAY_STYLE_UINT8:
|
||||
while (elements--)
|
||||
{
|
||||
if (*ptr_exp != *ptr_act)
|
||||
{
|
||||
UnityTestResultsFailBegin(lineNumber);
|
||||
UnityPrint(UnityStrElement);
|
||||
UnityPrintNumberByStyle((num_elements - elements - 1), UNITY_DISPLAY_STYLE_UINT);
|
||||
UnityPrint(UnityStrExpected);
|
||||
UnityPrintNumberByStyle(*ptr_exp, style);
|
||||
UnityPrint(UnityStrWas);
|
||||
UnityPrintNumberByStyle(*ptr_act, style);
|
||||
UnityAddMsgIfSpecified(msg);
|
||||
UNITY_FAIL_AND_BAIL;
|
||||
}
|
||||
ptr_exp += 1;
|
||||
ptr_act += 1;
|
||||
}
|
||||
break;
|
||||
case UNITY_DISPLAY_STYLE_HEX16:
|
||||
case UNITY_DISPLAY_STYLE_INT16:
|
||||
case UNITY_DISPLAY_STYLE_UINT16:
|
||||
while (elements--)
|
||||
{
|
||||
if (*(_US16*)ptr_exp != *(_US16*)ptr_act)
|
||||
{
|
||||
UnityTestResultsFailBegin(lineNumber);
|
||||
UnityPrint(UnityStrElement);
|
||||
UnityPrintNumberByStyle((num_elements - elements - 1), UNITY_DISPLAY_STYLE_UINT);
|
||||
UnityPrint(UnityStrExpected);
|
||||
UnityPrintNumberByStyle(*(_US16*)ptr_exp, style);
|
||||
UnityPrint(UnityStrWas);
|
||||
UnityPrintNumberByStyle(*(_US16*)ptr_act, style);
|
||||
UnityAddMsgIfSpecified(msg);
|
||||
UNITY_FAIL_AND_BAIL;
|
||||
}
|
||||
ptr_exp += 2;
|
||||
ptr_act += 2;
|
||||
}
|
||||
break;
|
||||
#ifdef UNITY_SUPPORT_64
|
||||
case UNITY_DISPLAY_STYLE_HEX64:
|
||||
case UNITY_DISPLAY_STYLE_INT64:
|
||||
case UNITY_DISPLAY_STYLE_UINT64:
|
||||
while (elements--)
|
||||
{
|
||||
if (*(_US64*)ptr_exp != *(_US64*)ptr_act)
|
||||
{
|
||||
UnityTestResultsFailBegin(lineNumber);
|
||||
UnityPrint(UnityStrElement);
|
||||
UnityPrintNumberByStyle((num_elements - elements - 1), UNITY_DISPLAY_STYLE_UINT);
|
||||
UnityPrint(UnityStrExpected);
|
||||
UnityPrintNumberByStyle(*(_US64*)ptr_exp, style);
|
||||
UnityPrint(UnityStrWas);
|
||||
UnityPrintNumberByStyle(*(_US64*)ptr_act, style);
|
||||
UnityAddMsgIfSpecified(msg);
|
||||
UNITY_FAIL_AND_BAIL;
|
||||
}
|
||||
ptr_exp += 8;
|
||||
ptr_act += 8;
|
||||
}
|
||||
break;
|
||||
#endif
|
||||
default:
|
||||
while (elements--)
|
||||
{
|
||||
if (*(_US32*)ptr_exp != *(_US32*)ptr_act)
|
||||
{
|
||||
UnityTestResultsFailBegin(lineNumber);
|
||||
UnityPrint(UnityStrElement);
|
||||
UnityPrintNumberByStyle((num_elements - elements - 1), UNITY_DISPLAY_STYLE_UINT);
|
||||
UnityPrint(UnityStrExpected);
|
||||
UnityPrintNumberByStyle(*(_US32*)ptr_exp, style);
|
||||
UnityPrint(UnityStrWas);
|
||||
UnityPrintNumberByStyle(*(_US32*)ptr_act, style);
|
||||
UnityAddMsgIfSpecified(msg);
|
||||
UNITY_FAIL_AND_BAIL;
|
||||
}
|
||||
ptr_exp += 4;
|
||||
ptr_act += 4;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------
|
||||
#ifndef UNITY_EXCLUDE_FLOAT
|
||||
void UnityAssertEqualFloatArray(const _UF* expected,
|
||||
const _UF* actual,
|
||||
const _UU32 num_elements,
|
||||
const char* msg,
|
||||
const UNITY_LINE_TYPE lineNumber)
|
||||
{
|
||||
_UU32 elements = num_elements;
|
||||
const _UF* ptr_expected = expected;
|
||||
const _UF* ptr_actual = actual;
|
||||
_UF diff, tol;
|
||||
|
||||
UNITY_SKIP_EXECUTION;
|
||||
|
||||
if (elements == 0)
|
||||
{
|
||||
UnityTestResultsFailBegin(lineNumber);
|
||||
UnityPrint(UnityStrPointless);
|
||||
UnityAddMsgIfSpecified(msg);
|
||||
UNITY_FAIL_AND_BAIL;
|
||||
}
|
||||
|
||||
if (UnityCheckArraysForNull((void*)expected, (void*)actual, lineNumber, msg) == 1)
|
||||
return;
|
||||
|
||||
while (elements--)
|
||||
{
|
||||
diff = *ptr_expected - *ptr_actual;
|
||||
if (diff < 0.0)
|
||||
diff = 0.0 - diff;
|
||||
tol = UNITY_FLOAT_PRECISION * *ptr_expected;
|
||||
if (tol < 0.0)
|
||||
tol = 0.0 - tol;
|
||||
if (diff > tol)
|
||||
{
|
||||
UnityTestResultsFailBegin(lineNumber);
|
||||
UnityPrint(UnityStrElement);
|
||||
UnityPrintNumberByStyle((num_elements - elements - 1), UNITY_DISPLAY_STYLE_UINT);
|
||||
#ifdef UNITY_FLOAT_VERBOSE
|
||||
UnityPrint(UnityStrExpected);
|
||||
UnityPrintFloat(*ptr_expected);
|
||||
UnityPrint(UnityStrWas);
|
||||
UnityPrintFloat(*ptr_actual);
|
||||
#else
|
||||
UnityPrint(UnityStrDelta);
|
||||
#endif
|
||||
UnityAddMsgIfSpecified(msg);
|
||||
UNITY_FAIL_AND_BAIL;
|
||||
}
|
||||
ptr_expected++;
|
||||
ptr_actual++;
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------
|
||||
void UnityAssertFloatsWithin(const _UF delta,
|
||||
const _UF expected,
|
||||
const _UF actual,
|
||||
const char* msg,
|
||||
const UNITY_LINE_TYPE lineNumber)
|
||||
{
|
||||
_UF diff = actual - expected;
|
||||
_UF pos_delta = delta;
|
||||
|
||||
UNITY_SKIP_EXECUTION;
|
||||
|
||||
if (diff < 0)
|
||||
{
|
||||
diff = 0.0f - diff;
|
||||
}
|
||||
if (pos_delta < 0)
|
||||
{
|
||||
pos_delta = 0.0f - pos_delta;
|
||||
}
|
||||
|
||||
if (pos_delta < diff)
|
||||
{
|
||||
UnityTestResultsFailBegin(lineNumber);
|
||||
#ifdef UNITY_FLOAT_VERBOSE
|
||||
UnityPrint(UnityStrExpected);
|
||||
UnityPrintFloat(expected);
|
||||
UnityPrint(UnityStrWas);
|
||||
UnityPrintFloat(actual);
|
||||
#else
|
||||
UnityPrint(UnityStrDelta);
|
||||
#endif
|
||||
UnityAddMsgIfSpecified(msg);
|
||||
UNITY_FAIL_AND_BAIL;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
//-----------------------------------------------
|
||||
void UnityAssertNumbersWithin( const _U_SINT delta,
|
||||
const _U_SINT expected,
|
||||
const _U_SINT actual,
|
||||
const char* msg,
|
||||
const UNITY_LINE_TYPE lineNumber,
|
||||
const UNITY_DISPLAY_STYLE_T style)
|
||||
{
|
||||
UNITY_SKIP_EXECUTION;
|
||||
|
||||
if ((style & UNITY_DISPLAY_RANGE_INT) == UNITY_DISPLAY_RANGE_INT)
|
||||
{
|
||||
if (actual > expected)
|
||||
Unity.CurrentTestFailed = ((actual - expected) > delta);
|
||||
else
|
||||
Unity.CurrentTestFailed = ((expected - actual) > delta);
|
||||
}
|
||||
else
|
||||
{
|
||||
if ((_U_UINT)actual > (_U_UINT)expected)
|
||||
Unity.CurrentTestFailed = ((_U_UINT)(actual - expected) > (_U_UINT)delta);
|
||||
else
|
||||
Unity.CurrentTestFailed = ((_U_UINT)(expected - actual) > (_U_UINT)delta);
|
||||
}
|
||||
|
||||
if (Unity.CurrentTestFailed)
|
||||
{
|
||||
UnityTestResultsFailBegin(lineNumber);
|
||||
UnityPrint(UnityStrDelta);
|
||||
UnityPrintNumberByStyle(delta, style);
|
||||
UnityPrint(UnityStrExpected);
|
||||
UnityPrintNumberByStyle(expected, style);
|
||||
UnityPrint(UnityStrWas);
|
||||
UnityPrintNumberByStyle(actual, style);
|
||||
UnityAddMsgIfSpecified(msg);
|
||||
UNITY_FAIL_AND_BAIL;
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------
|
||||
void UnityAssertEqualString(const char* expected,
|
||||
const char* actual,
|
||||
const char* msg,
|
||||
const UNITY_LINE_TYPE lineNumber)
|
||||
{
|
||||
_UU32 i;
|
||||
|
||||
UNITY_SKIP_EXECUTION;
|
||||
|
||||
// if both pointers not null compare the strings
|
||||
if (expected && actual)
|
||||
{
|
||||
for (i = 0; expected[i] || actual[i]; i++)
|
||||
{
|
||||
if (expected[i] != actual[i])
|
||||
{
|
||||
Unity.CurrentTestFailed = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{ // handle case of one pointers being null (if both null, test should pass)
|
||||
if (expected != actual)
|
||||
{
|
||||
Unity.CurrentTestFailed = 1;
|
||||
}
|
||||
}
|
||||
|
||||
if (Unity.CurrentTestFailed)
|
||||
{
|
||||
UnityTestResultsFailBegin(lineNumber);
|
||||
UnityPrintExpectedAndActualStrings(expected, actual);
|
||||
UnityAddMsgIfSpecified(msg);
|
||||
UNITY_FAIL_AND_BAIL;
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------
|
||||
void UnityAssertEqualStringArray( const char** expected,
|
||||
const char** actual,
|
||||
const _UU32 num_elements,
|
||||
const char* msg,
|
||||
const UNITY_LINE_TYPE lineNumber)
|
||||
{
|
||||
_UU32 i, j = 0;
|
||||
|
||||
UNITY_SKIP_EXECUTION;
|
||||
|
||||
// if no elements, it's an error
|
||||
if (num_elements == 0)
|
||||
{
|
||||
UnityTestResultsFailBegin(lineNumber);
|
||||
UnityPrint(UnityStrPointless);
|
||||
UnityAddMsgIfSpecified(msg);
|
||||
UNITY_FAIL_AND_BAIL;
|
||||
}
|
||||
|
||||
if (UnityCheckArraysForNull((void*)expected, (void*)actual, lineNumber, msg) == 1)
|
||||
return;
|
||||
|
||||
do
|
||||
{
|
||||
// if both pointers not null compare the strings
|
||||
if (expected[j] && actual[j])
|
||||
{
|
||||
for (i = 0; expected[j][i] || actual[j][i]; i++)
|
||||
{
|
||||
if (expected[j][i] != actual[j][i])
|
||||
{
|
||||
Unity.CurrentTestFailed = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{ // handle case of one pointers being null (if both null, test should pass)
|
||||
if (expected[j] != actual[j])
|
||||
{
|
||||
Unity.CurrentTestFailed = 1;
|
||||
}
|
||||
}
|
||||
|
||||
if (Unity.CurrentTestFailed)
|
||||
{
|
||||
UnityTestResultsFailBegin(lineNumber);
|
||||
if (num_elements > 1)
|
||||
{
|
||||
UnityPrint(UnityStrElement);
|
||||
UnityPrintNumberByStyle((num_elements - j - 1), UNITY_DISPLAY_STYLE_UINT);
|
||||
}
|
||||
UnityPrintExpectedAndActualStrings((const char*)(expected[j]), (const char*)(actual[j]));
|
||||
UnityAddMsgIfSpecified(msg);
|
||||
UNITY_FAIL_AND_BAIL;
|
||||
}
|
||||
} while (++j < num_elements);
|
||||
}
|
||||
|
||||
//-----------------------------------------------
|
||||
void UnityAssertEqualMemory( const void* expected,
|
||||
const void* actual,
|
||||
_UU32 length,
|
||||
_UU32 num_elements,
|
||||
const char* msg,
|
||||
const UNITY_LINE_TYPE lineNumber)
|
||||
{
|
||||
unsigned char* expected_ptr = (unsigned char*)expected;
|
||||
unsigned char* actual_ptr = (unsigned char*)actual;
|
||||
_UU32 elements = num_elements;
|
||||
|
||||
UNITY_SKIP_EXECUTION;
|
||||
|
||||
if ((elements == 0) || (length == 0))
|
||||
{
|
||||
UnityTestResultsFailBegin(lineNumber);
|
||||
UnityPrint(UnityStrPointless);
|
||||
UnityAddMsgIfSpecified(msg);
|
||||
UNITY_FAIL_AND_BAIL;
|
||||
}
|
||||
|
||||
if (UnityCheckArraysForNull((void*)expected, (void*)actual, lineNumber, msg) == 1)
|
||||
return;
|
||||
|
||||
while (elements--)
|
||||
{
|
||||
if (memcmp((const void*)expected_ptr, (const void*)actual_ptr, length) != 0)
|
||||
{
|
||||
Unity.CurrentTestFailed = 1;
|
||||
break;
|
||||
}
|
||||
expected_ptr += length;
|
||||
actual_ptr += length;
|
||||
}
|
||||
|
||||
if (Unity.CurrentTestFailed)
|
||||
{
|
||||
UnityTestResultsFailBegin(lineNumber);
|
||||
if (num_elements > 1)
|
||||
{
|
||||
UnityPrint(UnityStrElement);
|
||||
UnityPrintNumberByStyle((num_elements - elements - 1), UNITY_DISPLAY_STYLE_UINT);
|
||||
}
|
||||
UnityPrint(UnityStrMemory);
|
||||
UnityAddMsgIfSpecified(msg);
|
||||
UNITY_FAIL_AND_BAIL;
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------
|
||||
// Control Functions
|
||||
//-----------------------------------------------
|
||||
|
||||
void UnityFail(const char* msg, const UNITY_LINE_TYPE line)
|
||||
{
|
||||
UNITY_SKIP_EXECUTION;
|
||||
|
||||
UnityTestResultsBegin(Unity.TestFile, line);
|
||||
UnityPrint("FAIL");
|
||||
if (msg != NULL)
|
||||
{
|
||||
UNITY_OUTPUT_CHAR(':');
|
||||
if (msg[0] != ' ')
|
||||
{
|
||||
UNITY_OUTPUT_CHAR(' ');
|
||||
}
|
||||
UnityPrint(msg);
|
||||
}
|
||||
UNITY_FAIL_AND_BAIL;
|
||||
}
|
||||
|
||||
//-----------------------------------------------
|
||||
void UnityIgnore(const char* msg, const UNITY_LINE_TYPE line)
|
||||
{
|
||||
UNITY_SKIP_EXECUTION;
|
||||
|
||||
UnityTestResultsBegin(Unity.TestFile, line);
|
||||
UnityPrint("IGNORE");
|
||||
if (msg != NULL)
|
||||
{
|
||||
UNITY_OUTPUT_CHAR(':');
|
||||
UNITY_OUTPUT_CHAR(' ');
|
||||
UnityPrint(msg);
|
||||
}
|
||||
UNITY_IGNORE_AND_BAIL;
|
||||
}
|
||||
|
||||
//-----------------------------------------------
|
||||
void setUp(void);
|
||||
void tearDown(void);
|
||||
void UnityDefaultTestRun(UnityTestFunction Func, const char* FuncName, const int FuncLineNum)
|
||||
{
|
||||
Unity.CurrentTestName = FuncName;
|
||||
Unity.CurrentTestLineNumber = FuncLineNum;
|
||||
Unity.NumberOfTests++;
|
||||
if (TEST_PROTECT())
|
||||
{
|
||||
setUp();
|
||||
Func();
|
||||
}
|
||||
if (TEST_PROTECT() && !(Unity.CurrentTestIgnored))
|
||||
{
|
||||
tearDown();
|
||||
}
|
||||
UnityConcludeTest();
|
||||
}
|
||||
|
||||
//-----------------------------------------------
|
||||
void UnityBegin(void)
|
||||
{
|
||||
Unity.NumberOfTests = 0;
|
||||
}
|
||||
|
||||
//-----------------------------------------------
|
||||
int UnityEnd(void)
|
||||
{
|
||||
UnityPrint("-----------------------");
|
||||
UNITY_PRINT_EOL;
|
||||
UnityPrintNumber(Unity.NumberOfTests);
|
||||
UnityPrint(" Tests ");
|
||||
UnityPrintNumber(Unity.TestFailures);
|
||||
UnityPrint(" Failures ");
|
||||
UnityPrintNumber(Unity.TestIgnores);
|
||||
UnityPrint(" Ignored");
|
||||
UNITY_PRINT_EOL;
|
||||
if (Unity.TestFailures == 0U)
|
||||
{
|
||||
UnityPrint("OK");
|
||||
}
|
||||
else
|
||||
{
|
||||
UnityPrint("FAIL");
|
||||
}
|
||||
UNITY_PRINT_EOL;
|
||||
return Unity.TestFailures;
|
||||
}
|
||||
209
C/C(extra) ExtraAssignments/Stegano/Unity/unity.h
Normal file
209
C/C(extra) ExtraAssignments/Stegano/Unity/unity.h
Normal file
@@ -0,0 +1,209 @@
|
||||
/* ==========================================
|
||||
Unity Project - A Test Framework for C
|
||||
Copyright (c) 2007 Mike Karlesky, Mark VanderVoord, Greg Williams
|
||||
[Released under MIT License. Please refer to license.txt for details]
|
||||
========================================== */
|
||||
|
||||
#ifndef UNITY_FRAMEWORK_H
|
||||
#define UNITY_FRAMEWORK_H
|
||||
|
||||
#define UNITY
|
||||
|
||||
#include "unity_internals.h"
|
||||
|
||||
//-------------------------------------------------------
|
||||
// Configuration Options
|
||||
//-------------------------------------------------------
|
||||
|
||||
// Integers
|
||||
// - Unity assumes 32 bit integers by default
|
||||
// - If your compiler treats ints of a different size, define UNITY_INT_WIDTH
|
||||
|
||||
// Floats
|
||||
// - define UNITY_EXCLUDE_FLOAT to disallow floating point comparisons
|
||||
// - define UNITY_FLOAT_PRECISION to specify the precision to use when doing TEST_ASSERT_EQUAL_FLOAT
|
||||
// - define UNITY_FLOAT_TYPE to specify doubles instead of single precision floats
|
||||
// - define UNITY_FLOAT_VERBOSE to print floating point values in errors (uses sprintf)
|
||||
|
||||
// Output
|
||||
// - by default, Unity prints to standard out with putchar. define UNITY_OUTPUT_CHAR(a) with a different function if desired
|
||||
|
||||
// Optimization
|
||||
// - by default, line numbers are stored in unsigned shorts. Define UNITY_LINE_TYPE with a different type if your files are huge
|
||||
// - by default, test and failure counters are unsigned shorts. Define UNITY_COUNTER_TYPE with a different type if you want to save space or have more than 65535 Tests.
|
||||
|
||||
//-------------------------------------------------------
|
||||
// Test Running Macros
|
||||
//-------------------------------------------------------
|
||||
|
||||
#define TEST_PROTECT() (setjmp(Unity.AbortFrame) == 0)
|
||||
|
||||
#define TEST_ABORT() {longjmp(Unity.AbortFrame, 1);}
|
||||
|
||||
#ifndef RUN_TEST
|
||||
#define RUN_TEST(func, line_num) UnityDefaultTestRun(func, #func, line_num)
|
||||
#endif
|
||||
|
||||
#define TEST_LINE_NUM (Unity.CurrentTestLineNumber)
|
||||
#define TEST_IS_IGNORED (Unity.CurrentTestIgnored)
|
||||
|
||||
#define TEST_CASE(...)
|
||||
|
||||
//-------------------------------------------------------
|
||||
// Basic Fail and Ignore
|
||||
//-------------------------------------------------------
|
||||
|
||||
#define TEST_FAIL_MESSAGE(message) UNITY_TEST_FAIL(__LINE__, message)
|
||||
#define TEST_FAIL() UNITY_TEST_FAIL(__LINE__, NULL)
|
||||
#define TEST_IGNORE_MESSAGE(message) UNITY_TEST_IGNORE(__LINE__, message)
|
||||
#define TEST_IGNORE() UNITY_TEST_IGNORE(__LINE__, NULL)
|
||||
#define TEST_ONLY()
|
||||
|
||||
//-------------------------------------------------------
|
||||
// Test Asserts (simple)
|
||||
//-------------------------------------------------------
|
||||
|
||||
//Boolean
|
||||
#define TEST_ASSERT(condition) UNITY_TEST_ASSERT( (condition), __LINE__, " Expression Evaluated To FALSE")
|
||||
#define TEST_ASSERT_TRUE(condition) UNITY_TEST_ASSERT( (condition), __LINE__, " Expected TRUE Was FALSE")
|
||||
#define TEST_ASSERT_UNLESS(condition) UNITY_TEST_ASSERT( !(condition), __LINE__, " Expression Evaluated To TRUE")
|
||||
#define TEST_ASSERT_FALSE(condition) UNITY_TEST_ASSERT( !(condition), __LINE__, " Expected FALSE Was TRUE")
|
||||
#define TEST_ASSERT_NULL(pointer) UNITY_TEST_ASSERT_NULL( (pointer), __LINE__, " Expected NULL")
|
||||
#define TEST_ASSERT_NOT_NULL(pointer) UNITY_TEST_ASSERT_NOT_NULL((pointer), __LINE__, " Expected Non-NULL")
|
||||
|
||||
//Integers (of all sizes)
|
||||
#define TEST_ASSERT_EQUAL_INT(expected, actual) UNITY_TEST_ASSERT_EQUAL_INT((expected), (actual), __LINE__, NULL)
|
||||
#define TEST_ASSERT_EQUAL_INT8(expected, actual) UNITY_TEST_ASSERT_EQUAL_INT8((expected), (actual), __LINE__, NULL)
|
||||
#define TEST_ASSERT_EQUAL_INT16(expected, actual) UNITY_TEST_ASSERT_EQUAL_INT16((expected), (actual), __LINE__, NULL)
|
||||
#define TEST_ASSERT_EQUAL_INT32(expected, actual) UNITY_TEST_ASSERT_EQUAL_INT32((expected), (actual), __LINE__, NULL)
|
||||
#define TEST_ASSERT_EQUAL_INT64(expected, actual) UNITY_TEST_ASSERT_EQUAL_INT64((expected), (actual), __LINE__, NULL)
|
||||
#define TEST_ASSERT_EQUAL(expected, actual) UNITY_TEST_ASSERT_EQUAL_INT((expected), (actual), __LINE__, NULL)
|
||||
#define TEST_ASSERT_NOT_EQUAL(expected, actual) UNITY_TEST_ASSERT(((expected) != (actual)), __LINE__, " Expected Not-Equal")
|
||||
#define TEST_ASSERT_EQUAL_UINT(expected, actual) UNITY_TEST_ASSERT_EQUAL_UINT( (expected), (actual), __LINE__, NULL)
|
||||
#define TEST_ASSERT_EQUAL_UINT8(expected, actual) UNITY_TEST_ASSERT_EQUAL_UINT8( (expected), (actual), __LINE__, NULL)
|
||||
#define TEST_ASSERT_EQUAL_UINT16(expected, actual) UNITY_TEST_ASSERT_EQUAL_UINT16( (expected), (actual), __LINE__, NULL)
|
||||
#define TEST_ASSERT_EQUAL_UINT32(expected, actual) UNITY_TEST_ASSERT_EQUAL_UINT32( (expected), (actual), __LINE__, NULL)
|
||||
#define TEST_ASSERT_EQUAL_UINT64(expected, actual) UNITY_TEST_ASSERT_EQUAL_UINT64( (expected), (actual), __LINE__, NULL)
|
||||
#define TEST_ASSERT_EQUAL_HEX(expected, actual) UNITY_TEST_ASSERT_EQUAL_HEX32((expected), (actual), __LINE__, NULL)
|
||||
#define TEST_ASSERT_EQUAL_HEX8(expected, actual) UNITY_TEST_ASSERT_EQUAL_HEX8( (expected), (actual), __LINE__, NULL)
|
||||
#define TEST_ASSERT_EQUAL_HEX16(expected, actual) UNITY_TEST_ASSERT_EQUAL_HEX16((expected), (actual), __LINE__, NULL)
|
||||
#define TEST_ASSERT_EQUAL_HEX32(expected, actual) UNITY_TEST_ASSERT_EQUAL_HEX32((expected), (actual), __LINE__, NULL)
|
||||
#define TEST_ASSERT_EQUAL_HEX64(expected, actual) UNITY_TEST_ASSERT_EQUAL_HEX64((expected), (actual), __LINE__, NULL)
|
||||
#define TEST_ASSERT_BITS(mask, expected, actual) UNITY_TEST_ASSERT_BITS((mask), (expected), (actual), __LINE__, NULL)
|
||||
#define TEST_ASSERT_BITS_HIGH(mask, actual) UNITY_TEST_ASSERT_BITS((mask), (_UU32)(-1), (actual), __LINE__, NULL)
|
||||
#define TEST_ASSERT_BITS_LOW(mask, actual) UNITY_TEST_ASSERT_BITS((mask), (_UU32)(0), (actual), __LINE__, NULL)
|
||||
#define TEST_ASSERT_BIT_HIGH(bit, actual) UNITY_TEST_ASSERT_BITS(((_UU32)1 << bit), (_UU32)(-1), (actual), __LINE__, NULL)
|
||||
#define TEST_ASSERT_BIT_LOW(bit, actual) UNITY_TEST_ASSERT_BITS(((_UU32)1 << bit), (_UU32)(0), (actual), __LINE__, NULL)
|
||||
|
||||
//Integer Ranges (of all sizes)
|
||||
#define TEST_ASSERT_INT_WITHIN(delta, expected, actual) UNITY_TEST_ASSERT_INT_WITHIN(delta, expected, actual, __LINE__, NULL)
|
||||
#define TEST_ASSERT_UINT_WITHIN(delta, expected, actual) UNITY_TEST_ASSERT_UINT_WITHIN(delta, expected, actual, __LINE__, NULL)
|
||||
#define TEST_ASSERT_HEX_WITHIN(delta, expected, actual) UNITY_TEST_ASSERT_HEX32_WITHIN(delta, expected, actual, __LINE__, NULL)
|
||||
#define TEST_ASSERT_HEX8_WITHIN(delta, expected, actual) UNITY_TEST_ASSERT_HEX8_WITHIN(delta, expected, actual, __LINE__, NULL)
|
||||
#define TEST_ASSERT_HEX16_WITHIN(delta, expected, actual) UNITY_TEST_ASSERT_HEX16_WITHIN(delta, expected, actual, __LINE__, NULL)
|
||||
#define TEST_ASSERT_HEX32_WITHIN(delta, expected, actual) UNITY_TEST_ASSERT_HEX32_WITHIN(delta, expected, actual, __LINE__, NULL)
|
||||
#define TEST_ASSERT_HEX64_WITHIN(delta, expected, actual) UNITY_TEST_ASSERT_HEX64_WITHIN(delta, expected, actual, __LINE__, NULL)
|
||||
|
||||
//Structs and Strings
|
||||
#define TEST_ASSERT_EQUAL_PTR(expected, actual) UNITY_TEST_ASSERT_EQUAL_PTR((expected), (actual), __LINE__, NULL)
|
||||
#define TEST_ASSERT_EQUAL_STRING(expected, actual) UNITY_TEST_ASSERT_EQUAL_STRING(expected, actual, __LINE__, NULL)
|
||||
#define TEST_ASSERT_EQUAL_MEMORY(expected, actual, len) UNITY_TEST_ASSERT_EQUAL_MEMORY(expected, actual, len, __LINE__, NULL)
|
||||
|
||||
//Arrays
|
||||
#define TEST_ASSERT_EQUAL_INT_ARRAY(expected, actual, num_elements) UNITY_TEST_ASSERT_EQUAL_INT_ARRAY(expected, actual, num_elements, __LINE__, NULL)
|
||||
#define TEST_ASSERT_EQUAL_INT8_ARRAY(expected, actual, num_elements) UNITY_TEST_ASSERT_EQUAL_INT8_ARRAY(expected, actual, num_elements, __LINE__, NULL)
|
||||
#define TEST_ASSERT_EQUAL_INT16_ARRAY(expected, actual, num_elements) UNITY_TEST_ASSERT_EQUAL_INT16_ARRAY(expected, actual, num_elements, __LINE__, NULL)
|
||||
#define TEST_ASSERT_EQUAL_INT32_ARRAY(expected, actual, num_elements) UNITY_TEST_ASSERT_EQUAL_INT32_ARRAY(expected, actual, num_elements, __LINE__, NULL)
|
||||
#define TEST_ASSERT_EQUAL_INT64_ARRAY(expected, actual, num_elements) UNITY_TEST_ASSERT_EQUAL_INT64_ARRAY(expected, actual, num_elements, __LINE__, NULL)
|
||||
#define TEST_ASSERT_EQUAL_UINT_ARRAY(expected, actual, num_elements) UNITY_TEST_ASSERT_EQUAL_UINT_ARRAY(expected, actual, num_elements, __LINE__, NULL)
|
||||
#define TEST_ASSERT_EQUAL_UINT8_ARRAY(expected, actual, num_elements) UNITY_TEST_ASSERT_EQUAL_UINT8_ARRAY(expected, actual, num_elements, __LINE__, NULL)
|
||||
#define TEST_ASSERT_EQUAL_UINT16_ARRAY(expected, actual, num_elements) UNITY_TEST_ASSERT_EQUAL_UINT16_ARRAY(expected, actual, num_elements, __LINE__, NULL)
|
||||
#define TEST_ASSERT_EQUAL_UINT32_ARRAY(expected, actual, num_elements) UNITY_TEST_ASSERT_EQUAL_UINT32_ARRAY(expected, actual, num_elements, __LINE__, NULL)
|
||||
#define TEST_ASSERT_EQUAL_UINT64_ARRAY(expected, actual, num_elements) UNITY_TEST_ASSERT_EQUAL_UINT64_ARRAY(expected, actual, num_elements, __LINE__, NULL)
|
||||
#define TEST_ASSERT_EQUAL_HEX_ARRAY(expected, actual, num_elements) UNITY_TEST_ASSERT_EQUAL_HEX32_ARRAY(expected, actual, num_elements, __LINE__, NULL)
|
||||
#define TEST_ASSERT_EQUAL_HEX8_ARRAY(expected, actual, num_elements) UNITY_TEST_ASSERT_EQUAL_HEX8_ARRAY(expected, actual, num_elements, __LINE__, NULL)
|
||||
#define TEST_ASSERT_EQUAL_HEX16_ARRAY(expected, actual, num_elements) UNITY_TEST_ASSERT_EQUAL_HEX16_ARRAY(expected, actual, num_elements, __LINE__, NULL)
|
||||
#define TEST_ASSERT_EQUAL_HEX32_ARRAY(expected, actual, num_elements) UNITY_TEST_ASSERT_EQUAL_HEX32_ARRAY(expected, actual, num_elements, __LINE__, NULL)
|
||||
#define TEST_ASSERT_EQUAL_HEX64_ARRAY(expected, actual, num_elements) UNITY_TEST_ASSERT_EQUAL_HEX64_ARRAY(expected, actual, num_elements, __LINE__, NULL)
|
||||
#define TEST_ASSERT_EQUAL_STRING_ARRAY(expected, actual, num_elements) UNITY_TEST_ASSERT_EQUAL_STRING_ARRAY(expected, actual, num_elements, __LINE__, NULL)
|
||||
#define TEST_ASSERT_EQUAL_MEMORY_ARRAY(expected, actual, len, num_elements) UNITY_TEST_ASSERT_EQUAL_MEMORY_ARRAY(expected, actual, len, num_elements, __LINE__, NULL)
|
||||
|
||||
//Floating Point (If Enabled)
|
||||
#define TEST_ASSERT_FLOAT_WITHIN(delta, expected, actual) UNITY_TEST_ASSERT_FLOAT_WITHIN(delta, expected, actual, __LINE__, NULL)
|
||||
#define TEST_ASSERT_EQUAL_FLOAT(expected, actual) UNITY_TEST_ASSERT_EQUAL_FLOAT(expected, actual, __LINE__, NULL)
|
||||
#define TEST_ASSERT_EQUAL_FLOAT_ARRAY(expected, actual, num_elements) UNITY_TEST_ASSERT_EQUAL_FLOAT_ARRAY(expected, actual, num_elements, __LINE__, NULL)
|
||||
|
||||
//-------------------------------------------------------
|
||||
// Test Asserts (with additional messages)
|
||||
//-------------------------------------------------------
|
||||
|
||||
//Boolean
|
||||
#define TEST_ASSERT_MESSAGE(condition, message) UNITY_TEST_ASSERT( (condition), __LINE__, message)
|
||||
#define TEST_ASSERT_TRUE_MESSAGE(condition, message) UNITY_TEST_ASSERT( (condition), __LINE__, message)
|
||||
#define TEST_ASSERT_UNLESS_MESSAGE(condition, message) UNITY_TEST_ASSERT( !(condition), __LINE__, message)
|
||||
#define TEST_ASSERT_FALSE_MESSAGE(condition, message) UNITY_TEST_ASSERT( !(condition), __LINE__, message)
|
||||
#define TEST_ASSERT_NULL_MESSAGE(pointer, message) UNITY_TEST_ASSERT_NULL( (pointer), __LINE__, message)
|
||||
#define TEST_ASSERT_NOT_NULL_MESSAGE(pointer, message) UNITY_TEST_ASSERT_NOT_NULL((pointer), __LINE__, message)
|
||||
|
||||
//Integers (of all sizes)
|
||||
#define TEST_ASSERT_EQUAL_INT_MESSAGE(expected, actual, message) UNITY_TEST_ASSERT_EQUAL_INT((expected), (actual), __LINE__, message)
|
||||
#define TEST_ASSERT_EQUAL_INT8_MESSAGE(expected, actual, message) UNITY_TEST_ASSERT_EQUAL_INT8((expected), (actual), __LINE__, message)
|
||||
#define TEST_ASSERT_EQUAL_INT16_MESSAGE(expected, actual, message) UNITY_TEST_ASSERT_EQUAL_INT16((expected), (actual), __LINE__, message)
|
||||
#define TEST_ASSERT_EQUAL_INT32_MESSAGE(expected, actual, message) UNITY_TEST_ASSERT_EQUAL_INT32((expected), (actual), __LINE__, message)
|
||||
#define TEST_ASSERT_EQUAL_INT64_MESSAGE(expected, actual, message) UNITY_TEST_ASSERT_EQUAL_INT64((expected), (actual), __LINE__, message)
|
||||
#define TEST_ASSERT_EQUAL_MESSAGE(expected, actual, message) UNITY_TEST_ASSERT_EQUAL_INT((expected), (actual), __LINE__, message)
|
||||
#define TEST_ASSERT_NOT_EQUAL_MESSAGE(expected, actual, message) UNITY_TEST_ASSERT(((expected) != (actual)), __LINE__, message)
|
||||
#define TEST_ASSERT_EQUAL_UINT_MESSAGE(expected, actual, message) UNITY_TEST_ASSERT_EQUAL_UINT( (expected), (actual), __LINE__, message)
|
||||
#define TEST_ASSERT_EQUAL_UINT8_MESSAGE(expected, actual, message) UNITY_TEST_ASSERT_EQUAL_UINT8( (expected), (actual), __LINE__, message)
|
||||
#define TEST_ASSERT_EQUAL_UINT16_MESSAGE(expected, actual, message) UNITY_TEST_ASSERT_EQUAL_UINT16( (expected), (actual), __LINE__, message)
|
||||
#define TEST_ASSERT_EQUAL_UINT32_MESSAGE(expected, actual, message) UNITY_TEST_ASSERT_EQUAL_UINT32( (expected), (actual), __LINE__, message)
|
||||
#define TEST_ASSERT_EQUAL_UINT64_MESSAGE(expected, actual, message) UNITY_TEST_ASSERT_EQUAL_UINT64( (expected), (actual), __LINE__, message)
|
||||
#define TEST_ASSERT_EQUAL_HEX_MESSAGE(expected, actual, message) UNITY_TEST_ASSERT_EQUAL_HEX32((expected), (actual), __LINE__, message)
|
||||
#define TEST_ASSERT_EQUAL_HEX8_MESSAGE(expected, actual, message) UNITY_TEST_ASSERT_EQUAL_HEX8( (expected), (actual), __LINE__, message)
|
||||
#define TEST_ASSERT_EQUAL_HEX16_MESSAGE(expected, actual, message) UNITY_TEST_ASSERT_EQUAL_HEX16((expected), (actual), __LINE__, message)
|
||||
#define TEST_ASSERT_EQUAL_HEX32_MESSAGE(expected, actual, message) UNITY_TEST_ASSERT_EQUAL_HEX32((expected), (actual), __LINE__, message)
|
||||
#define TEST_ASSERT_EQUAL_HEX64_MESSAGE(expected, actual, message) UNITY_TEST_ASSERT_EQUAL_HEX64((expected), (actual), __LINE__, message)
|
||||
#define TEST_ASSERT_BITS_MESSAGE(mask, expected, actual, message) UNITY_TEST_ASSERT_BITS((mask), (expected), (actual), __LINE__, message)
|
||||
#define TEST_ASSERT_BITS_HIGH_MESSAGE(mask, actual, message) UNITY_TEST_ASSERT_BITS((mask), (_UU32)(-1), (actual), __LINE__, message)
|
||||
#define TEST_ASSERT_BITS_LOW_MESSAGE(mask, actual, message) UNITY_TEST_ASSERT_BITS((mask), (_UU32)(0), (actual), __LINE__, message)
|
||||
#define TEST_ASSERT_BIT_HIGH_MESSAGE(bit, actual, message) UNITY_TEST_ASSERT_BITS(((_UU32)1 << bit), (_UU32)(-1), (actual), __LINE__, message)
|
||||
#define TEST_ASSERT_BIT_LOW_MESSAGE(bit, actual, message) UNITY_TEST_ASSERT_BITS(((_UU32)1 << bit), (_UU32)(0), (actual), __LINE__, message)
|
||||
|
||||
//Integer Ranges (of all sizes)
|
||||
#define TEST_ASSERT_INT_WITHIN_MESSAGE(delta, expected, actual, message) UNITY_TEST_ASSERT_INT_WITHIN(delta, expected, actual, __LINE__, message)
|
||||
#define TEST_ASSERT_UINT_WITHIN_MESSAGE(delta, expected, actual, message) UNITY_TEST_ASSERT_UINT_WITHIN(delta, expected, actual, __LINE__, message)
|
||||
#define TEST_ASSERT_HEX_WITHIN_MESSAGE(delta, expected, actual, message) UNITY_TEST_ASSERT_HEX32_WITHIN(delta, expected, actual, __LINE__, message)
|
||||
#define TEST_ASSERT_HEX8_WITHIN_MESSAGE(delta, expected, actual, message) UNITY_TEST_ASSERT_HEX8_WITHIN(delta, expected, actual, __LINE__, message)
|
||||
#define TEST_ASSERT_HEX16_WITHIN_MESSAGE(delta, expected, actual, message) UNITY_TEST_ASSERT_HEX16_WITHIN(delta, expected, actual, __LINE__, message)
|
||||
#define TEST_ASSERT_HEX32_WITHIN_MESSAGE(delta, expected, actual, message) UNITY_TEST_ASSERT_HEX32_WITHIN(delta, expected, actual, __LINE__, message)
|
||||
#define TEST_ASSERT_HEX64_WITHIN_MESSAGE(delta, expected, actual, message) UNITY_TEST_ASSERT_HEX64_WITHIN(delta, expected, actual, __LINE__, message)
|
||||
|
||||
//Structs and Strings
|
||||
#define TEST_ASSERT_EQUAL_PTR_MESSAGE(expected, actual, message) UNITY_TEST_ASSERT_EQUAL_PTR(expected, actual, __LINE__, message)
|
||||
#define TEST_ASSERT_EQUAL_STRING_MESSAGE(expected, actual, message) UNITY_TEST_ASSERT_EQUAL_STRING(expected, actual, __LINE__, message)
|
||||
#define TEST_ASSERT_EQUAL_MEMORY_MESSAGE(expected, actual, len, message) UNITY_TEST_ASSERT_EQUAL_MEMORY(expected, actual, len, __LINE__, message)
|
||||
|
||||
//Arrays
|
||||
#define TEST_ASSERT_EQUAL_INT_ARRAY_MESSAGE(expected, actual, num_elements, message) UNITY_TEST_ASSERT_EQUAL_INT_ARRAY(expected, actual, num_elements, __LINE__, message)
|
||||
#define TEST_ASSERT_EQUAL_INT8_ARRAY_MESSAGE(expected, actual, num_elements, message) UNITY_TEST_ASSERT_EQUAL_INT8_ARRAY(expected, actual, num_elements, __LINE__, message)
|
||||
#define TEST_ASSERT_EQUAL_INT16_ARRAY_MESSAGE(expected, actual, num_elements, message) UNITY_TEST_ASSERT_EQUAL_INT16_ARRAY(expected, actual, num_elements, __LINE__, message)
|
||||
#define TEST_ASSERT_EQUAL_INT32_ARRAY_MESSAGE(expected, actual, num_elements, message) UNITY_TEST_ASSERT_EQUAL_INT32_ARRAY(expected, actual, num_elements, __LINE__, message)
|
||||
#define TEST_ASSERT_EQUAL_INT64_ARRAY_MESSAGE(expected, actual, num_elements, message) UNITY_TEST_ASSERT_EQUAL_INT64_ARRAY(expected, actual, num_elements, __LINE__, message)
|
||||
#define TEST_ASSERT_EQUAL_UINT_ARRAY_MESSAGE(expected, actual, num_elements, message) UNITY_TEST_ASSERT_EQUAL_UINT_ARRAY(expected, actual, num_elements, __LINE__, message)
|
||||
#define TEST_ASSERT_EQUAL_UINT8_ARRAY_MESSAGE(expected, actual, num_elements, message) UNITY_TEST_ASSERT_EQUAL_UINT8_ARRAY(expected, actual, num_elements, __LINE__, message)
|
||||
#define TEST_ASSERT_EQUAL_UINT16_ARRAY_MESSAGE(expected, actual, num_elements, message) UNITY_TEST_ASSERT_EQUAL_UINT16_ARRAY(expected, actual, num_elements, __LINE__, message)
|
||||
#define TEST_ASSERT_EQUAL_UINT32_ARRAY_MESSAGE(expected, actual, num_elements, message) UNITY_TEST_ASSERT_EQUAL_UINT32_ARRAY(expected, actual, num_elements, __LINE__, message)
|
||||
#define TEST_ASSERT_EQUAL_UINT64_ARRAY_MESSAGE(expected, actual, num_elements, message) UNITY_TEST_ASSERT_EQUAL_UINT64_ARRAY(expected, actual, num_elements, __LINE__, message)
|
||||
#define TEST_ASSERT_EQUAL_HEX_ARRAY_MESSAGE(expected, actual, num_elements, message) UNITY_TEST_ASSERT_EQUAL_HEX32_ARRAY(expected, actual, num_elements, __LINE__, message)
|
||||
#define TEST_ASSERT_EQUAL_HEX8_ARRAY_MESSAGE(expected, actual, num_elements, message) UNITY_TEST_ASSERT_EQUAL_HEX8_ARRAY(expected, actual, num_elements, __LINE__, message)
|
||||
#define TEST_ASSERT_EQUAL_HEX16_ARRAY_MESSAGE(expected, actual, num_elements, message) UNITY_TEST_ASSERT_EQUAL_HEX16_ARRAY(expected, actual, num_elements, __LINE__, message)
|
||||
#define TEST_ASSERT_EQUAL_HEX32_ARRAY_MESSAGE(expected, actual, num_elements, message) UNITY_TEST_ASSERT_EQUAL_HEX32_ARRAY(expected, actual, num_elements, __LINE__, message)
|
||||
#define TEST_ASSERT_EQUAL_HEX64_ARRAY_MESSAGE(expected, actual, num_elements, message) UNITY_TEST_ASSERT_EQUAL_HEX64_ARRAY(expected, actual, num_elements, __LINE__, message)
|
||||
#define TEST_ASSERT_EQUAL_STRING_ARRAY_MESSAGE(expected, actual, num_elements, message) UNITY_TEST_ASSERT_EQUAL_STRING_ARRAY(expected, actual, num_elements, __LINE__, message)
|
||||
#define TEST_ASSERT_EQUAL_MEMORY_ARRAY_MESSAGE(expected, actual, len, num_elements, message) UNITY_TEST_ASSERT_EQUAL_MEMORY_ARRAY(expected, actual, len, num_elements, __LINE__, message)
|
||||
|
||||
//Floating Point (If Enabled)
|
||||
#define TEST_ASSERT_FLOAT_WITHIN_MESSAGE(delta, expected, actual, message) UNITY_TEST_ASSERT_FLOAT_WITHIN(delta, expected, actual, __LINE__, message)
|
||||
#define TEST_ASSERT_EQUAL_FLOAT_MESSAGE(expected, actual, message) UNITY_TEST_ASSERT_EQUAL_FLOAT(expected, actual, __LINE__, message)
|
||||
#define TEST_ASSERT_EQUAL_FLOAT_ARRAY_MESSAGE(expected, actual, num_elements, message) UNITY_TEST_ASSERT_EQUAL_FLOAT_ARRAY(expected, actual, num_elements, __LINE__, message)
|
||||
#endif
|
||||
356
C/C(extra) ExtraAssignments/Stegano/Unity/unity_internals.h
Normal file
356
C/C(extra) ExtraAssignments/Stegano/Unity/unity_internals.h
Normal file
@@ -0,0 +1,356 @@
|
||||
/* ==========================================
|
||||
Unity Project - A Test Framework for C
|
||||
Copyright (c) 2007 Mike Karlesky, Mark VanderVoord, Greg Williams
|
||||
[Released under MIT License. Please refer to license.txt for details]
|
||||
========================================== */
|
||||
|
||||
#ifndef UNITY_INTERNALS_H
|
||||
#define UNITY_INTERNALS_H
|
||||
|
||||
#include <stdio.h>
|
||||
#include <setjmp.h>
|
||||
|
||||
//-------------------------------------------------------
|
||||
// Int Support
|
||||
//-------------------------------------------------------
|
||||
|
||||
#ifndef UNITY_INT_WIDTH
|
||||
#define UNITY_INT_WIDTH (32)
|
||||
#endif
|
||||
|
||||
#ifndef UNITY_LONG_WIDTH
|
||||
#define UNITY_LONG_WIDTH (32)
|
||||
#endif
|
||||
|
||||
#if (UNITY_INT_WIDTH == 32)
|
||||
typedef unsigned char _UU8;
|
||||
typedef unsigned short _UU16;
|
||||
typedef unsigned int _UU32;
|
||||
typedef signed char _US8;
|
||||
typedef signed short _US16;
|
||||
typedef signed int _US32;
|
||||
#elif (UNITY_INT_WIDTH == 16)
|
||||
typedef unsigned char _UU8;
|
||||
typedef unsigned int _UU16;
|
||||
typedef unsigned long _UU32;
|
||||
typedef signed char _US8;
|
||||
typedef signed int _US16;
|
||||
typedef signed long _US32;
|
||||
#else
|
||||
#error Invalid UNITY_INT_WIDTH specified! (16 or 32 are supported)
|
||||
#endif
|
||||
|
||||
//-------------------------------------------------------
|
||||
// 64-bit Support
|
||||
//-------------------------------------------------------
|
||||
|
||||
#ifndef UNITY_SUPPORT_64
|
||||
|
||||
//No 64-bit Support
|
||||
typedef _UU32 _U_UINT;
|
||||
typedef _US32 _U_SINT;
|
||||
|
||||
#else
|
||||
|
||||
//64-bit Support
|
||||
#if (UNITY_LONG_WIDTH == 32)
|
||||
typedef unsigned long long _UU64;
|
||||
typedef signed long long _US64;
|
||||
#elif (UNITY_LONG_WIDTH == 64)
|
||||
typedef unsigned long _UU64;
|
||||
typedef signed long _US64;
|
||||
#else
|
||||
#error Invalid UNITY_LONG_WIDTH specified! (32 or 64 are supported)
|
||||
#endif
|
||||
typedef _UU64 _U_UINT;
|
||||
typedef _US64 _U_SINT;
|
||||
|
||||
#endif
|
||||
|
||||
//-------------------------------------------------------
|
||||
// Pointer Support
|
||||
//-------------------------------------------------------
|
||||
|
||||
#ifndef UNITY_POINTER_WIDTH
|
||||
#define UNITY_POINTER_WIDTH (32)
|
||||
#endif
|
||||
|
||||
#if (UNITY_POINTER_WIDTH == 32)
|
||||
typedef _UU32 _UP;
|
||||
#define UNITY_DISPLAY_STYLE_POINTER UNITY_DISPLAY_STYLE_HEX32
|
||||
#elif (UNITY_POINTER_WIDTH == 64)
|
||||
typedef _UU64 _UP;
|
||||
#define UNITY_DISPLAY_STYLE_POINTER UNITY_DISPLAY_STYLE_HEX64
|
||||
#elif (UNITY_POINTER_WIDTH == 16)
|
||||
typedef _UU16 _UP;
|
||||
#define UNITY_DISPLAY_STYLE_POINTER UNITY_DISPLAY_STYLE_HEX16
|
||||
#else
|
||||
#error Invalid UNITY_POINTER_WIDTH specified! (16, 32 or 64 are supported)
|
||||
#endif
|
||||
|
||||
//-------------------------------------------------------
|
||||
// Float Support
|
||||
//-------------------------------------------------------
|
||||
|
||||
#ifdef UNITY_EXCLUDE_FLOAT
|
||||
|
||||
//No Floating Point Support
|
||||
#undef UNITY_FLOAT_PRECISION
|
||||
#undef UNITY_FLOAT_TYPE
|
||||
#undef UNITY_FLOAT_VERBOSE
|
||||
|
||||
#else
|
||||
|
||||
//Floating Point Support
|
||||
#ifndef UNITY_FLOAT_PRECISION
|
||||
#define UNITY_FLOAT_PRECISION (0.00001f)
|
||||
#endif
|
||||
#ifndef UNITY_FLOAT_TYPE
|
||||
#define UNITY_FLOAT_TYPE float
|
||||
#endif
|
||||
typedef UNITY_FLOAT_TYPE _UF;
|
||||
|
||||
#endif
|
||||
|
||||
//-------------------------------------------------------
|
||||
// Output Method
|
||||
//-------------------------------------------------------
|
||||
|
||||
#ifndef UNITY_OUTPUT_CHAR
|
||||
//Default to using putchar, which is defined in stdio.h above
|
||||
#define UNITY_OUTPUT_CHAR(a) putchar(a)
|
||||
#else
|
||||
//If defined as something else, make sure we declare it here so it's ready for use
|
||||
extern int UNITY_OUTPUT_CHAR(int);
|
||||
#endif
|
||||
|
||||
//-------------------------------------------------------
|
||||
// Footprint
|
||||
//-------------------------------------------------------
|
||||
|
||||
#ifndef UNITY_LINE_TYPE
|
||||
#define UNITY_LINE_TYPE unsigned short
|
||||
#endif
|
||||
|
||||
#ifndef UNITY_COUNTER_TYPE
|
||||
#define UNITY_COUNTER_TYPE unsigned short
|
||||
#endif
|
||||
|
||||
//-------------------------------------------------------
|
||||
// Internal Structs Needed
|
||||
//-------------------------------------------------------
|
||||
|
||||
typedef void (*UnityTestFunction)(void);
|
||||
|
||||
#define UNITY_DISPLAY_RANGE_INT (0x10)
|
||||
#define UNITY_DISPLAY_RANGE_UINT (0x20)
|
||||
#define UNITY_DISPLAY_RANGE_HEX (0x40)
|
||||
#define UNITY_DISPLAY_RANGE_AUTO (0x80)
|
||||
|
||||
typedef enum
|
||||
{
|
||||
UNITY_DISPLAY_STYLE_INT = 4 + UNITY_DISPLAY_RANGE_INT + UNITY_DISPLAY_RANGE_AUTO,
|
||||
UNITY_DISPLAY_STYLE_INT8 = 1 + UNITY_DISPLAY_RANGE_INT,
|
||||
UNITY_DISPLAY_STYLE_INT16 = 2 + UNITY_DISPLAY_RANGE_INT,
|
||||
UNITY_DISPLAY_STYLE_INT32 = 4 + UNITY_DISPLAY_RANGE_INT,
|
||||
#ifdef UNITY_SUPPORT_64
|
||||
UNITY_DISPLAY_STYLE_INT64 = 8 + UNITY_DISPLAY_RANGE_INT,
|
||||
#endif
|
||||
UNITY_DISPLAY_STYLE_UINT = 4 + UNITY_DISPLAY_RANGE_UINT + UNITY_DISPLAY_RANGE_AUTO,
|
||||
UNITY_DISPLAY_STYLE_UINT8 = 1 + UNITY_DISPLAY_RANGE_UINT,
|
||||
UNITY_DISPLAY_STYLE_UINT16 = 2 + UNITY_DISPLAY_RANGE_UINT,
|
||||
UNITY_DISPLAY_STYLE_UINT32 = 4 + UNITY_DISPLAY_RANGE_UINT,
|
||||
#ifdef UNITY_SUPPORT_64
|
||||
UNITY_DISPLAY_STYLE_UINT64 = 8 + UNITY_DISPLAY_RANGE_UINT,
|
||||
#endif
|
||||
UNITY_DISPLAY_STYLE_HEX8 = 1 + UNITY_DISPLAY_RANGE_HEX,
|
||||
UNITY_DISPLAY_STYLE_HEX16 = 2 + UNITY_DISPLAY_RANGE_HEX,
|
||||
UNITY_DISPLAY_STYLE_HEX32 = 4 + UNITY_DISPLAY_RANGE_HEX,
|
||||
#ifdef UNITY_SUPPORT_64
|
||||
UNITY_DISPLAY_STYLE_HEX64 = 8 + UNITY_DISPLAY_RANGE_HEX,
|
||||
#endif
|
||||
} UNITY_DISPLAY_STYLE_T;
|
||||
|
||||
struct _Unity
|
||||
{
|
||||
const char* TestFile;
|
||||
const char* CurrentTestName;
|
||||
_UU32 CurrentTestLineNumber;
|
||||
UNITY_COUNTER_TYPE NumberOfTests;
|
||||
UNITY_COUNTER_TYPE TestFailures;
|
||||
UNITY_COUNTER_TYPE TestIgnores;
|
||||
UNITY_COUNTER_TYPE CurrentTestFailed;
|
||||
UNITY_COUNTER_TYPE CurrentTestIgnored;
|
||||
jmp_buf AbortFrame;
|
||||
};
|
||||
|
||||
extern struct _Unity Unity;
|
||||
|
||||
//-------------------------------------------------------
|
||||
// Test Suite Management
|
||||
//-------------------------------------------------------
|
||||
|
||||
void UnityBegin(void);
|
||||
int UnityEnd(void);
|
||||
|
||||
void UnityConcludeTest(void);
|
||||
void UnityDefaultTestRun(UnityTestFunction Func, const char* FuncName, const int FuncLineNum);
|
||||
|
||||
//-------------------------------------------------------
|
||||
// Test Output
|
||||
//-------------------------------------------------------
|
||||
|
||||
void UnityPrint(const char* string);
|
||||
void UnityPrintMask(const _U_UINT mask, const _U_UINT number);
|
||||
void UnityPrintNumberByStyle(const _U_SINT number, const UNITY_DISPLAY_STYLE_T style);
|
||||
void UnityPrintNumber(const _U_SINT number);
|
||||
void UnityPrintNumberUnsigned(const _U_UINT number);
|
||||
void UnityPrintNumberHex(const _U_UINT number, const char nibbles);
|
||||
|
||||
#ifdef UNITY_FLOAT_VERBOSE
|
||||
void UnityPrintFloat(const _UF number);
|
||||
#endif
|
||||
|
||||
//-------------------------------------------------------
|
||||
// Test Assertion Fuctions
|
||||
//-------------------------------------------------------
|
||||
// Use the macros below this section instead of calling
|
||||
// these directly. The macros have a consistent naming
|
||||
// convention and will pull in file and line information
|
||||
// for you.
|
||||
|
||||
void UnityAssertEqualNumber(const _U_SINT expected,
|
||||
const _U_SINT actual,
|
||||
const char* msg,
|
||||
const UNITY_LINE_TYPE lineNumber,
|
||||
const UNITY_DISPLAY_STYLE_T style);
|
||||
|
||||
void UnityAssertEqualIntArray(const _U_SINT* expected,
|
||||
const _U_SINT* actual,
|
||||
const _UU32 num_elements,
|
||||
const char* msg,
|
||||
const UNITY_LINE_TYPE lineNumber,
|
||||
const UNITY_DISPLAY_STYLE_T style);
|
||||
|
||||
void UnityAssertBits(const _U_SINT mask,
|
||||
const _U_SINT expected,
|
||||
const _U_SINT actual,
|
||||
const char* msg,
|
||||
const UNITY_LINE_TYPE lineNumber);
|
||||
|
||||
void UnityAssertEqualString(const char* expected,
|
||||
const char* actual,
|
||||
const char* msg,
|
||||
const UNITY_LINE_TYPE lineNumber);
|
||||
|
||||
void UnityAssertEqualStringArray( const char** expected,
|
||||
const char** actual,
|
||||
const _UU32 num_elements,
|
||||
const char* msg,
|
||||
const UNITY_LINE_TYPE lineNumber);
|
||||
|
||||
void UnityAssertEqualMemory( const void* expected,
|
||||
const void* actual,
|
||||
const _UU32 length,
|
||||
const _UU32 num_elements,
|
||||
const char* msg,
|
||||
const UNITY_LINE_TYPE lineNumber);
|
||||
|
||||
void UnityAssertNumbersWithin(const _U_SINT delta,
|
||||
const _U_SINT expected,
|
||||
const _U_SINT actual,
|
||||
const char* msg,
|
||||
const UNITY_LINE_TYPE lineNumber,
|
||||
const UNITY_DISPLAY_STYLE_T style);
|
||||
|
||||
void UnityFail(const char* message, const UNITY_LINE_TYPE line);
|
||||
|
||||
void UnityIgnore(const char* message, const UNITY_LINE_TYPE line);
|
||||
|
||||
#ifndef UNITY_EXCLUDE_FLOAT
|
||||
void UnityAssertFloatsWithin(const _UF delta,
|
||||
const _UF expected,
|
||||
const _UF actual,
|
||||
const char* msg,
|
||||
const UNITY_LINE_TYPE lineNumber);
|
||||
|
||||
void UnityAssertEqualFloatArray(const _UF* expected,
|
||||
const _UF* actual,
|
||||
const _UU32 num_elements,
|
||||
const char* msg,
|
||||
const UNITY_LINE_TYPE lineNumber);
|
||||
#endif
|
||||
|
||||
//-------------------------------------------------------
|
||||
// Basic Fail and Ignore
|
||||
//-------------------------------------------------------
|
||||
|
||||
#define UNITY_TEST_FAIL(line, message) UnityFail( (message), (UNITY_LINE_TYPE)line);
|
||||
#define UNITY_TEST_IGNORE(line, message) UnityIgnore( (message), (UNITY_LINE_TYPE)line);
|
||||
|
||||
//-------------------------------------------------------
|
||||
// Test Asserts
|
||||
//-------------------------------------------------------
|
||||
|
||||
#define UNITY_TEST_ASSERT(condition, line, message) if (condition) {} else {UNITY_TEST_FAIL((UNITY_LINE_TYPE)line, message);}
|
||||
#define UNITY_TEST_ASSERT_NULL(pointer, line, message) UNITY_TEST_ASSERT(((pointer) == NULL), (UNITY_LINE_TYPE)line, message)
|
||||
#define UNITY_TEST_ASSERT_NOT_NULL(pointer, line, message) UNITY_TEST_ASSERT(((pointer) != NULL), (UNITY_LINE_TYPE)line, message)
|
||||
|
||||
#define UNITY_TEST_ASSERT_EQUAL_INT(expected, actual, line, message) UnityAssertEqualNumber((_U_SINT)(expected), (_U_SINT)(actual), (message), (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_INT)
|
||||
#define UNITY_TEST_ASSERT_EQUAL_INT8(expected, actual, line, message) UnityAssertEqualNumber((_U_SINT)(expected), (_U_SINT)(actual), (message), (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_INT)
|
||||
#define UNITY_TEST_ASSERT_EQUAL_INT16(expected, actual, line, message) UnityAssertEqualNumber((_U_SINT)(expected), (_U_SINT)(actual), (message), (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_INT)
|
||||
#define UNITY_TEST_ASSERT_EQUAL_INT32(expected, actual, line, message) UnityAssertEqualNumber((_U_SINT)(expected), (_U_SINT)(actual), (message), (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_INT)
|
||||
#define UNITY_TEST_ASSERT_EQUAL_UINT(expected, actual, line, message) UnityAssertEqualNumber((_U_SINT)(expected), (_U_SINT)(actual), (message), (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_UINT)
|
||||
#define UNITY_TEST_ASSERT_EQUAL_UINT8(expected, actual, line, message) UnityAssertEqualNumber((_U_SINT)(expected), (_U_SINT)(actual), (message), (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_UINT)
|
||||
#define UNITY_TEST_ASSERT_EQUAL_UINT16(expected, actual, line, message) UnityAssertEqualNumber((_U_SINT)(expected), (_U_SINT)(actual), (message), (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_UINT)
|
||||
#define UNITY_TEST_ASSERT_EQUAL_UINT32(expected, actual, line, message) UnityAssertEqualNumber((_U_SINT)(expected), (_U_SINT)(actual), (message), (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_UINT)
|
||||
#define UNITY_TEST_ASSERT_EQUAL_HEX8(expected, actual, line, message) UnityAssertEqualNumber((_U_SINT)(expected), (_U_SINT)(actual), (message), (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_HEX8)
|
||||
#define UNITY_TEST_ASSERT_EQUAL_HEX16(expected, actual, line, message) UnityAssertEqualNumber((_U_SINT)(expected), (_U_SINT)(actual), (message), (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_HEX16)
|
||||
#define UNITY_TEST_ASSERT_EQUAL_HEX32(expected, actual, line, message) UnityAssertEqualNumber((_U_SINT)(expected), (_U_SINT)(actual), (message), (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_HEX32)
|
||||
#define UNITY_TEST_ASSERT_BITS(mask, expected, actual, line, message) UnityAssertBits((_U_SINT)(mask), (_U_SINT)(expected), (_U_SINT)(actual), (message), (UNITY_LINE_TYPE)line)
|
||||
|
||||
#define UNITY_TEST_ASSERT_INT_WITHIN(delta, expected, actual, line, message) UnityAssertNumbersWithin((_U_SINT)(delta), (_U_SINT)(expected), (_U_SINT)(actual), NULL, (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_INT)
|
||||
#define UNITY_TEST_ASSERT_UINT_WITHIN(delta, expected, actual, line, message) UnityAssertNumbersWithin((_U_SINT)(delta), (_U_SINT)(expected), (_U_SINT)(actual), NULL, (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_UINT)
|
||||
#define UNITY_TEST_ASSERT_HEX8_WITHIN(delta, expected, actual, line, message) UnityAssertNumbersWithin((_U_SINT)(delta), (_U_SINT)(expected), (_U_SINT)(actual), NULL, (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_HEX8)
|
||||
#define UNITY_TEST_ASSERT_HEX16_WITHIN(delta, expected, actual, line, message) UnityAssertNumbersWithin((_U_SINT)(delta), (_U_SINT)(expected), (_U_SINT)(actual), NULL, (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_HEX16)
|
||||
#define UNITY_TEST_ASSERT_HEX32_WITHIN(delta, expected, actual, line, message) UnityAssertNumbersWithin((_U_SINT)(delta), (_U_SINT)(expected), (_U_SINT)(actual), NULL, (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_HEX32)
|
||||
#define UNITY_TEST_ASSERT_HEX64_WITHIN(delta, expected, actual, line, message) UnityAssertNumbersWithin((_U_SINT)(delta), (_U_SINT)(expected), (_U_SINT)(actual), NULL, (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_HEX64)
|
||||
|
||||
#define UNITY_TEST_ASSERT_EQUAL_PTR(expected, actual, line, message) UnityAssertEqualNumber((_U_SINT)(_UP)(expected), (_U_SINT)(_UP)(actual), (message), (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_POINTER)
|
||||
#define UNITY_TEST_ASSERT_EQUAL_STRING(expected, actual, line, message) UnityAssertEqualString((const char*)(expected), (const char*)(actual), (message), (UNITY_LINE_TYPE)line)
|
||||
#define UNITY_TEST_ASSERT_EQUAL_MEMORY(expected, actual, len, line, message) UnityAssertEqualMemory((void*)(expected), (void*)(actual), (_UU32)(len), 1, (message), (UNITY_LINE_TYPE)line)
|
||||
|
||||
#define UNITY_TEST_ASSERT_EQUAL_INT_ARRAY(expected, actual, num_elements, line, message) UnityAssertEqualIntArray((const _U_SINT*)(expected), (const _U_SINT*)(actual), (_UU32)(num_elements), (message), (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_INT)
|
||||
#define UNITY_TEST_ASSERT_EQUAL_INT8_ARRAY(expected, actual, num_elements, line, message) UnityAssertEqualIntArray((const _U_SINT*)(expected), (const _U_SINT*)(actual), (_UU32)(num_elements), (message), (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_INT8)
|
||||
#define UNITY_TEST_ASSERT_EQUAL_INT16_ARRAY(expected, actual, num_elements, line, message) UnityAssertEqualIntArray((const _U_SINT*)(expected), (const _U_SINT*)(actual), (_UU32)(num_elements), (message), (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_INT16)
|
||||
#define UNITY_TEST_ASSERT_EQUAL_INT32_ARRAY(expected, actual, num_elements, line, message) UnityAssertEqualIntArray((const _U_SINT*)(expected), (const _U_SINT*)(actual), (_UU32)(num_elements), (message), (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_INT32)
|
||||
#define UNITY_TEST_ASSERT_EQUAL_UINT_ARRAY(expected, actual, num_elements, line, message) UnityAssertEqualIntArray((const _U_SINT*)(expected), (const _U_SINT*)(actual), (_UU32)(num_elements), (message), (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_UINT)
|
||||
#define UNITY_TEST_ASSERT_EQUAL_UINT8_ARRAY(expected, actual, num_elements, line, message) UnityAssertEqualIntArray((const _U_SINT*)(expected), (const _U_SINT*)(actual), (_UU32)(num_elements), (message), (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_UINT8)
|
||||
#define UNITY_TEST_ASSERT_EQUAL_UINT16_ARRAY(expected, actual, num_elements, line, message) UnityAssertEqualIntArray((const _U_SINT*)(expected), (const _U_SINT*)(actual), (_UU32)(num_elements), (message), (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_UINT16)
|
||||
#define UNITY_TEST_ASSERT_EQUAL_UINT32_ARRAY(expected, actual, num_elements, line, message) UnityAssertEqualIntArray((const _U_SINT*)(expected), (const _U_SINT*)(actual), (_UU32)(num_elements), (message), (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_UINT32)
|
||||
#define UNITY_TEST_ASSERT_EQUAL_HEX8_ARRAY(expected, actual, num_elements, line, message) UnityAssertEqualIntArray((const _U_SINT*)(expected), (const _U_SINT*)(actual), (_UU32)(num_elements), (message), (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_HEX8)
|
||||
#define UNITY_TEST_ASSERT_EQUAL_HEX16_ARRAY(expected, actual, num_elements, line, message) UnityAssertEqualIntArray((const _U_SINT*)(expected), (const _U_SINT*)(actual), (_UU32)(num_elements), (message), (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_HEX16)
|
||||
#define UNITY_TEST_ASSERT_EQUAL_HEX32_ARRAY(expected, actual, num_elements, line, message) UnityAssertEqualIntArray((const _U_SINT*)(expected), (const _U_SINT*)(actual), (_UU32)(num_elements), (message), (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_HEX32)
|
||||
#define UNITY_TEST_ASSERT_EQUAL_STRING_ARRAY(expected, actual, num_elements, line, message) UnityAssertEqualStringArray((const char**)(expected), (const char**)(actual), (_UU32)(num_elements), (message), (UNITY_LINE_TYPE)line)
|
||||
#define UNITY_TEST_ASSERT_EQUAL_MEMORY_ARRAY(expected, actual, len, num_elements, line, message) UnityAssertEqualMemory((void*)(expected), (void*)(actual), (_UU32)(len), (_UU32)(num_elements), (message), (UNITY_LINE_TYPE)line)
|
||||
|
||||
#ifdef UNITY_SUPPORT_64
|
||||
#define UNITY_TEST_ASSERT_EQUAL_INT64(expected, actual, line, message) UnityAssertEqualNumber((_U_SINT)(expected), (_U_SINT)(actual), (message), (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_INT64)
|
||||
#define UNITY_TEST_ASSERT_EQUAL_UINT64(expected, actual, line, message) UnityAssertEqualNumber((_U_SINT)(expected), (_U_SINT)(actual), (message), (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_UINT64)
|
||||
#define UNITY_TEST_ASSERT_EQUAL_HEX64(expected, actual, line, message) UnityAssertEqualNumber((_U_SINT)(expected), (_U_SINT)(actual), (message), (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_HEX64)
|
||||
#define UNITY_TEST_ASSERT_EQUAL_INT64_ARRAY(expected, actual, num_elements, line, message) UnityAssertEqualIntArray((const _U_SINT*)(expected), (const _U_SINT*)(actual), (_UU32)(num_elements), (message), (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_INT64)
|
||||
#define UNITY_TEST_ASSERT_EQUAL_UINT64_ARRAY(expected, actual, num_elements, line, message) UnityAssertEqualIntArray((const _U_SINT*)(expected), (const _U_SINT*)(actual), (_UU32)(num_elements), (message), (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_UINT64)
|
||||
#define UNITY_TEST_ASSERT_EQUAL_HEX64_ARRAY(expected, actual, num_elements, line, message) UnityAssertEqualIntArray((const _U_SINT*)(expected), (const _U_SINT*)(actual), (_UU32)(num_elements), (message), (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_HEX64)
|
||||
#endif
|
||||
|
||||
#ifdef UNITY_EXCLUDE_FLOAT
|
||||
#define UNITY_TEST_ASSERT_FLOAT_WITHIN(delta, expected, actual, line, message) UNITY_TEST_FAIL((UNITY_LINE_TYPE)line, "Unity Floating Point Disabled")
|
||||
#define UNITY_TEST_ASSERT_EQUAL_FLOAT(expected, actual, line, message) UNITY_TEST_FAIL((UNITY_LINE_TYPE)line, "Unity Floating Point Disabled")
|
||||
#define UNITY_TEST_ASSERT_EQUAL_FLOAT_ARRAY(expected, actual, num_elements, line, message) UNITY_TEST_FAIL((UNITY_LINE_TYPE)line, "Unity Floating Point Disabled")
|
||||
#else
|
||||
#define UNITY_TEST_ASSERT_FLOAT_WITHIN(delta, expected, actual, line, message) UnityAssertFloatsWithin((_UF)(delta), (_UF)(expected), (_UF)(actual), (message), (UNITY_LINE_TYPE)line)
|
||||
#define UNITY_TEST_ASSERT_EQUAL_FLOAT(expected, actual, line, message) UNITY_TEST_ASSERT_FLOAT_WITHIN((_UF)(expected) * (_UF)UNITY_FLOAT_PRECISION, (_UF)expected, (_UF)actual, (UNITY_LINE_TYPE)line, message)
|
||||
#define UNITY_TEST_ASSERT_EQUAL_FLOAT_ARRAY(expected, actual, num_elements, line, message) UnityAssertEqualFloatArray((_UF*)(expected), (_UF*)(actual), (_UU32)(num_elements), (message), (UNITY_LINE_TYPE)line)
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,97 @@
|
||||
#include "unity_test_module.h"
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <stdbool.h>
|
||||
#include "unity.h"
|
||||
|
||||
void (*unity_setUp_ptr)(void) = NULL;
|
||||
void (*unit_tearDown_ptr)(void) = NULL;
|
||||
|
||||
#ifdef UNITY_USE_MODULE_SETUP_TEARDOWN
|
||||
|
||||
void setUp()
|
||||
{
|
||||
if(unity_setUp_ptr != NULL) unity_setUp_ptr();
|
||||
}
|
||||
|
||||
void tearDown()
|
||||
{
|
||||
if(unit_tearDown_ptr != NULL) unit_tearDown_ptr();
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
void UnityRegisterSetupTearDown( void(*setUp)(void), void(*tearDown)(void) )
|
||||
{
|
||||
unity_setUp_ptr = setUp;
|
||||
unit_tearDown_ptr = tearDown;
|
||||
}
|
||||
|
||||
void UnityUnregisterSetupTearDown(void)
|
||||
{
|
||||
unity_setUp_ptr = NULL;
|
||||
unit_tearDown_ptr = NULL;
|
||||
}
|
||||
|
||||
UnityTestModule* UnityTestModuleFind(
|
||||
UnityTestModule* modules,
|
||||
size_t number_of_modules,
|
||||
char* wantedModule)
|
||||
{
|
||||
for(size_t i = 0; i < number_of_modules; i++) {
|
||||
if(strcmp(wantedModule, modules[i].name) == 0) {
|
||||
return &modules[i];
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void UnityTestModuleRunRequestedModules(
|
||||
int number_of_requested_modules,
|
||||
char* requested_modules_names[],
|
||||
UnityTestModule* allModules,
|
||||
size_t number_of_modules )
|
||||
{
|
||||
for(int i = 0; i < number_of_requested_modules; i++)
|
||||
{
|
||||
UnityTestModule* module = UnityTestModuleFind(allModules,
|
||||
number_of_modules, requested_modules_names[i]);
|
||||
|
||||
if(module != NULL)
|
||||
{
|
||||
module->run_tests();
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("Ignoring: could not find requested module: %s\n",
|
||||
requested_modules_names[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int UnityTestModuleRun(
|
||||
int argc,
|
||||
char * argv[],
|
||||
UnityTestModule* allModules,
|
||||
size_t number_of_modules)
|
||||
{
|
||||
UnityBegin();
|
||||
|
||||
bool moduleRequests = (argc > 1);
|
||||
|
||||
if(moduleRequests)
|
||||
{
|
||||
UnityTestModuleRunRequestedModules(argc-1, &argv[1],
|
||||
allModules, number_of_modules);
|
||||
}
|
||||
else
|
||||
{
|
||||
for(int i = 0; i < number_of_modules; i++)
|
||||
{
|
||||
allModules[i].run_tests();
|
||||
}
|
||||
}
|
||||
|
||||
return UnityEnd();
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
#ifndef UNITY_TEST_MODULE_H
|
||||
#define UNITY_TEST_MODULE_H
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
typedef struct {
|
||||
char name[24];
|
||||
void(*run_tests)(void);
|
||||
} UnityTestModule;
|
||||
|
||||
void UnityRegisterSetupTearDown( void(*setUp)(void), void(*tearDown)(void) );
|
||||
void UnityUnregisterSetupTearDown(void);
|
||||
|
||||
UnityTestModule* UnityTestModuleFind(
|
||||
UnityTestModule* modules,
|
||||
size_t number_of_modules,
|
||||
char* wantedModule);
|
||||
|
||||
void UnityTestModuleRunRequestedModules(
|
||||
int number_of_requested_modules,
|
||||
char* requested_modules_names[],
|
||||
UnityTestModule* allModules,
|
||||
size_t number_of_modules );
|
||||
|
||||
int UnityTestModuleRun(
|
||||
int argc,
|
||||
char * argv[],
|
||||
UnityTestModule* allModules,
|
||||
size_t number_of_modules);
|
||||
|
||||
#endif
|
||||
43
C/C(extra) ExtraAssignments/Stegano/bmp.h
Normal file
43
C/C(extra) ExtraAssignments/Stegano/bmp.h
Normal file
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
* bmp.h
|
||||
*
|
||||
* Created on: Feb 23, 2012
|
||||
* Author: student
|
||||
*/
|
||||
|
||||
#ifndef BMP_H_
|
||||
#define BMP_H_
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
// datatypes obtained from http://en.wikipedia.org/wiki/BMP_file_format
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint8_t magic[2];
|
||||
} __attribute__ (( packed )) BMP_MAGIC_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint32_t filesz;
|
||||
uint16_t creator1;
|
||||
uint16_t creator2;
|
||||
uint32_t bmp_offset;
|
||||
} __attribute__ (( packed )) BMP_FILE_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint32_t header_sz;
|
||||
int32_t width;
|
||||
int32_t height;
|
||||
uint16_t nplanes;
|
||||
uint16_t bitspp;
|
||||
uint32_t compress_type;
|
||||
uint32_t bmp_bytesz;
|
||||
int32_t hres;
|
||||
int32_t vres;
|
||||
uint32_t ncolors;
|
||||
uint32_t nimpcolors;
|
||||
} __attribute__ (( packed )) BMP_INFO_t;
|
||||
|
||||
#endif /* BMP_H_ */
|
||||
6
C/C(extra) ExtraAssignments/Stegano/challengelevel.json
Normal file
6
C/C(extra) ExtraAssignments/Stegano/challengelevel.json
Normal file
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"challenge":{
|
||||
"level":["shows"] ,
|
||||
"durationHours": 8
|
||||
}
|
||||
}
|
||||
168
C/C(extra) ExtraAssignments/Stegano/stegano.c
Normal file
168
C/C(extra) ExtraAssignments/Stegano/stegano.c
Normal file
@@ -0,0 +1,168 @@
|
||||
/*
|
||||
* stegano.c
|
||||
*
|
||||
* Created on: Nov 6, 2011
|
||||
* Author: J. Geurts
|
||||
*/
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "bmp.h"
|
||||
#include "resource_detector.h"
|
||||
#include "stegano.h"
|
||||
|
||||
#define MAX_FILENAME 80
|
||||
|
||||
extern uint8_t SteganoGetSubstring(
|
||||
uint8_t Src, uint8_t SrcPos, uint8_t NrOfBits, uint8_t DestPos)
|
||||
/* description: get a substring of bits from a uint8_t (i.e. a byte)
|
||||
*
|
||||
* example: SteganoGetSubstring (Src, 3, 4, 1) with Src=ABCDEFGH (bit H is LSB)
|
||||
* = 000BCDE0
|
||||
*
|
||||
* parameters:
|
||||
* Src: byte to get the substring from
|
||||
* SrcPos: position of the first bit of the substring (LSB=0)
|
||||
* NrOfBits: length of the substring
|
||||
* DestPos: position of the first bits of the destination substring
|
||||
*
|
||||
* return:
|
||||
* substring, starting at DestPos
|
||||
*/
|
||||
{
|
||||
// to be implemented
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
// should be static in real life, but would give a compiling error in the
|
||||
// unchanged code because this function is not yet used
|
||||
static void ReadHdr(
|
||||
FILE* FilePtr, BMP_MAGIC_t* Magic, BMP_FILE_t* File,
|
||||
BMP_INFO_t* Info)
|
||||
/*
|
||||
* description: read the header of a bmp File, and store the data in the
|
||||
* provided parameters
|
||||
*
|
||||
* parameters:
|
||||
* FilePtr: file, opened for reading
|
||||
* Magic: output-parameter to store the read BMP_MAGIC_t structure
|
||||
* File: output-parameter to store the read BMP_FILE_t structure
|
||||
* Info: output-parameter to store the read BMP_INFO_t structure
|
||||
*
|
||||
* Note: caller should provide enough memory for parameters 'Magic', 'File' and
|
||||
* 'Info'
|
||||
*/
|
||||
{
|
||||
// to be implemented
|
||||
}
|
||||
|
||||
|
||||
// should be static in real life, but would give a compiling error in the
|
||||
// unchanged code because this function is not yet used
|
||||
static void WriteHdr(
|
||||
FILE* FilePtr, BMP_MAGIC_t* Magic, BMP_FILE_t* File,
|
||||
BMP_INFO_t* Info)
|
||||
/*
|
||||
* description: write the header of a bmp File, where the data comes from the
|
||||
* provided parameters
|
||||
*
|
||||
* parameters:
|
||||
* FilePtr: file, opened for writing
|
||||
* Magic: input-parameter with a BMP_MAGIC_t structure
|
||||
* File: input-parameter with a BMP_FILE_t structure
|
||||
* Info: input-parameter with a BMP_INFO_t structure
|
||||
*
|
||||
*/
|
||||
{
|
||||
// to be implemented
|
||||
}
|
||||
|
||||
|
||||
extern void SteganoMultiplex(const char* File0, const char* File1)
|
||||
{
|
||||
FILE* FilePtr0 = NULL;
|
||||
FILE* FilePtr1 = NULL;
|
||||
FILE* FilePtr2 = NULL;
|
||||
char buf[MAX_FILENAME];
|
||||
|
||||
for (int NrBits = 0; NrBits <= 8; NrBits++)
|
||||
{
|
||||
// NrBits: number of bits for the hidden image
|
||||
sprintf(buf, "mux_%s_%s_%d.bmp", File0, File1, NrBits);
|
||||
FilePtr0 = fopen(File0, "rb");
|
||||
FilePtr1 = fopen(File1, "rb");
|
||||
FilePtr2 = fopen(buf, "wb");
|
||||
|
||||
// to be implemented
|
||||
|
||||
|
||||
fclose(FilePtr0);
|
||||
fclose(FilePtr1);
|
||||
fclose(FilePtr2);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
extern void SteganoMultiplexText(const char* File0, const char* File1)
|
||||
{
|
||||
FILE* FilePtr0 = NULL;
|
||||
FILE* FilePtr1 = NULL;
|
||||
FILE* FilePtr2 = NULL;
|
||||
char buf[MAX_FILENAME];
|
||||
|
||||
sprintf(buf, "mux_%s_%s.bmp", File0, File1);
|
||||
FilePtr0 = fopen(File0, "rb");
|
||||
FilePtr1 = fopen(File1, "rb");
|
||||
FilePtr2 = fopen(buf, "wb");
|
||||
|
||||
// to be implemented
|
||||
|
||||
|
||||
fclose(FilePtr0);
|
||||
fclose(FilePtr1);
|
||||
fclose(FilePtr2);
|
||||
}
|
||||
|
||||
|
||||
extern void
|
||||
SteganoDemultiplex(const char* File0, const char* File1, const char* File2)
|
||||
{
|
||||
FILE* FilePtr0 = NULL;
|
||||
FILE* FilePtr1 = NULL;
|
||||
FILE* FilePtr2 = NULL;
|
||||
|
||||
FilePtr0 = fopen(File0, "rb");
|
||||
FilePtr1 = fopen(File1, "wb");
|
||||
FilePtr2 = fopen(File2, "wb");
|
||||
|
||||
// to be implemented
|
||||
|
||||
|
||||
fclose(FilePtr0);
|
||||
fclose(FilePtr1);
|
||||
fclose(FilePtr2);
|
||||
}
|
||||
|
||||
|
||||
extern void
|
||||
SteganoDemultiplexText(const char* File0, const char* File1, const char* File2)
|
||||
{
|
||||
FILE* FilePtr0 = NULL;
|
||||
FILE* FilePtr1 = NULL;
|
||||
FILE* FilePtr2 = NULL;
|
||||
|
||||
FilePtr0 = fopen(File0, "rb"); /* binair lezen */
|
||||
FilePtr1 = fopen(File1, "wb"); /* binair schrijven */
|
||||
FilePtr2 = fopen(File2, "wb"); /* binair schrijven */
|
||||
|
||||
// to be implemented
|
||||
|
||||
|
||||
fclose(FilePtr0);
|
||||
fclose(FilePtr1);
|
||||
fclose(FilePtr2);
|
||||
}
|
||||
23
C/C(extra) ExtraAssignments/Stegano/stegano.h
Normal file
23
C/C(extra) ExtraAssignments/Stegano/stegano.h
Normal file
@@ -0,0 +1,23 @@
|
||||
/*
|
||||
* stegano.h
|
||||
*
|
||||
* Created on: Nov 6, 2011
|
||||
* Author: J. Geurts
|
||||
*/
|
||||
|
||||
#ifndef STEGANO_H_
|
||||
#define STEGANO_H_
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
extern uint8_t SteganoGetSubstring(
|
||||
uint8_t src, uint8_t src_pos, uint8_t nrof_bits, uint8_t dest_pos);
|
||||
|
||||
extern void SteganoMultiplex(const char* File0, const char* File1);
|
||||
extern void SteganoMultiplexText(const char* File0, const char* File1);
|
||||
extern void SteganoDemultiplex(
|
||||
const char* File0, const char* File1, const char* File2);
|
||||
extern void SteganoDemultiplexText(
|
||||
const char* File0, const char* File1, const char* File2);
|
||||
|
||||
#endif
|
||||
128
C/C(extra) ExtraAssignments/Stegano/stegano_main.c
Normal file
128
C/C(extra) ExtraAssignments/Stegano/stegano_main.c
Normal file
@@ -0,0 +1,128 @@
|
||||
/*
|
||||
* main.c
|
||||
*
|
||||
* Created on: Nov 6, 2011
|
||||
* Author: student
|
||||
*/
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "bmp.h"
|
||||
#include "resource_detector.h"
|
||||
#include "stegano.h"
|
||||
|
||||
#define MAX_STRLEN 80
|
||||
|
||||
static bool WithMenu = true;
|
||||
|
||||
static int GetInt(const char* Message)
|
||||
{
|
||||
char Line[MAX_STRLEN];
|
||||
char* Result = NULL;
|
||||
int Value = -1;
|
||||
|
||||
if (WithMenu)
|
||||
{
|
||||
printf("%s", Message);
|
||||
}
|
||||
Result = fgets(Line, sizeof(Line), stdin);
|
||||
if (Result != NULL)
|
||||
{
|
||||
sscanf(Result, "%d", &Value);
|
||||
}
|
||||
|
||||
return Value;
|
||||
}
|
||||
|
||||
static void GetStr(const char* Message, char* Str)
|
||||
{
|
||||
char Line[MAX_STRLEN];
|
||||
char* Result = NULL;
|
||||
|
||||
if (WithMenu)
|
||||
{
|
||||
printf("%s", Message);
|
||||
}
|
||||
Result = fgets(Line, sizeof(Line), stdin);
|
||||
if (Result != NULL)
|
||||
{
|
||||
sscanf(Result, "%s", Str);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
extern int main(int argc, char* argv[])
|
||||
{
|
||||
char File0[MAX_STRLEN];
|
||||
char File1[MAX_STRLEN];
|
||||
char File2[MAX_STRLEN];
|
||||
int Choice;
|
||||
bool Quit = false;
|
||||
|
||||
printf("PRC assignment 'SteganoC' (version 2)\n"
|
||||
"-------------------------------------\n");
|
||||
|
||||
if (argc != 1)
|
||||
{
|
||||
fprintf(stderr, "%s: argc=%d\n", argv[0], argc);
|
||||
}
|
||||
|
||||
while (!Quit)
|
||||
{
|
||||
if (WithMenu)
|
||||
{
|
||||
printf("\n\nMENU\n"
|
||||
"===================\n"
|
||||
"[1] multiplex\n"
|
||||
"[2] multiplex text\n"
|
||||
"[3] demultiplex\n"
|
||||
"[4] demultiplex text\n"
|
||||
"[8] show/hide menu\n"
|
||||
"[9] Quit\n");
|
||||
}
|
||||
Choice = GetInt("Choice: ");
|
||||
|
||||
switch (Choice)
|
||||
{
|
||||
case 1:
|
||||
GetStr("enter input file (visible): ", File0);
|
||||
GetStr("enter input file (hidden): ", File1);
|
||||
SteganoMultiplex(File0, File1);
|
||||
break;
|
||||
case 2:
|
||||
GetStr("enter input file (visible): ", File0);
|
||||
GetStr("enter input file (text): ", File1);
|
||||
SteganoMultiplexText(File0, File1);
|
||||
break;
|
||||
case 3:
|
||||
GetStr("enter input file: ", File0);
|
||||
GetStr("enter output file (visible): ", File1);
|
||||
GetStr("enter output file (hidden): ", File2);
|
||||
SteganoDemultiplex(File0, File1, File2);
|
||||
break;
|
||||
case 4:
|
||||
GetStr("enter input file: ", File0);
|
||||
GetStr("enter output file (visible): ", File1);
|
||||
GetStr("enter output file (text): ", File2);
|
||||
SteganoDemultiplexText(File0, File1, File2);
|
||||
break;
|
||||
case 8:
|
||||
if (WithMenu)
|
||||
{
|
||||
printf("printing of MENU is disabled\n");
|
||||
}
|
||||
WithMenu = !WithMenu;
|
||||
break;
|
||||
case 9:
|
||||
Quit = true;
|
||||
break;
|
||||
default:
|
||||
printf("ERROR: invalid Choice: %d\n", Choice);
|
||||
break;
|
||||
}
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
435
C/C(extra) ExtraAssignments/Stegano/stegano_test.c
Normal file
435
C/C(extra) ExtraAssignments/Stegano/stegano_test.c
Normal file
@@ -0,0 +1,435 @@
|
||||
/* auteur : F.J. Hurkmans
|
||||
* datum : November 4th 2013
|
||||
* code : Ansi C
|
||||
* versie : 1
|
||||
*/
|
||||
|
||||
#include "bmp.h"
|
||||
#include "stegano.h"
|
||||
#include "unity.h"
|
||||
|
||||
#include <limits.h>
|
||||
#include <stdlib.h>
|
||||
#include <time.h>
|
||||
|
||||
#include "resource_detector.h"
|
||||
|
||||
// I rather dislike keeping line numbers updated, so I made my own macro to
|
||||
// ditch the line number
|
||||
#define MY_RUN_TEST(func) RUN_TEST(func, 0)
|
||||
|
||||
|
||||
void setUp(void)
|
||||
{
|
||||
// This is run before EACH test
|
||||
}
|
||||
|
||||
void tearDown(void)
|
||||
{
|
||||
// This is run after EACH test
|
||||
const char* FilenamesToDeleteAfterTest[] = {
|
||||
"demux_ImageCitroen2Cv.bmp",
|
||||
"demux_TextFontys.txt",
|
||||
"demux_ImageRedFerrari_0.bmp",
|
||||
"demux_ImageRedFerrari_1.bmp",
|
||||
"demux_ImageRedFerrari_4.bmp",
|
||||
"demux_ImageRedFerrari_7.bmp",
|
||||
"demux_ImageRedFerrari_8.bmp",
|
||||
"demux_ImageTrabant_0.bmp",
|
||||
"demux_ImageTrabant_1.bmp",
|
||||
"demux_ImageTrabant_4.bmp",
|
||||
"demux_ImageTrabant_7.bmp",
|
||||
"demux_ImageTrabant_8.bmp",
|
||||
"mux_ImageCitroen2Cv.bmp_TextFontys.txt.bmp",
|
||||
"mux_ImageTrabant.bmp_ImageRedFerrari.bmp.bmp",
|
||||
"mux_ImageTrabant.bmp_ImageRedFerrari.bmp_0.bmp",
|
||||
"mux_ImageTrabant.bmp_ImageRedFerrari.bmp_1.bmp",
|
||||
"mux_ImageTrabant.bmp_ImageRedFerrari.bmp_2.bmp",
|
||||
"mux_ImageTrabant.bmp_ImageRedFerrari.bmp_3.bmp",
|
||||
"mux_ImageTrabant.bmp_ImageRedFerrari.bmp_4.bmp",
|
||||
"mux_ImageTrabant.bmp_ImageRedFerrari.bmp_5.bmp",
|
||||
"mux_ImageTrabant.bmp_ImageRedFerrari.bmp_6.bmp",
|
||||
"mux_ImageTrabant.bmp_ImageRedFerrari.bmp_7.bmp",
|
||||
"mux_ImageTrabant.bmp_ImageRedFerrari.bmp_8.bmp"
|
||||
};
|
||||
|
||||
for (size_t i = 0; i < (sizeof(FilenamesToDeleteAfterTest) /
|
||||
sizeof(FilenamesToDeleteAfterTest[0]));
|
||||
i++)
|
||||
{
|
||||
remove(FilenamesToDeleteAfterTest[i]);
|
||||
}
|
||||
}
|
||||
|
||||
static int GetFileSize(FILE* FilePtr)
|
||||
{
|
||||
int CurrPos = ftell(FilePtr);
|
||||
int EndPos = 0;
|
||||
TEST_ASSERT_EQUAL(0, fseek(FilePtr, 0L, SEEK_END));
|
||||
EndPos = ftell(FilePtr);
|
||||
TEST_ASSERT_EQUAL(0, fseek(FilePtr, CurrPos, SEEK_SET));
|
||||
return EndPos;
|
||||
}
|
||||
|
||||
static void Assert2FilesEqual(char* File1, char* File2)
|
||||
{
|
||||
const size_t BufferSize = 4096;
|
||||
FILE* File1Ptr = fopen(File1, "rb");
|
||||
TEST_ASSERT_NOT_NULL(File1Ptr);
|
||||
FILE* File2Ptr = fopen(File2, "rb");
|
||||
TEST_ASSERT_NOT_NULL(File2Ptr);
|
||||
|
||||
int File1Size = GetFileSize(File1Ptr);
|
||||
int File2Size = GetFileSize(File2Ptr);
|
||||
|
||||
TEST_ASSERT_EQUAL(File1Size, File2Size);
|
||||
|
||||
char* File1Buffer = malloc(BufferSize);
|
||||
TEST_ASSERT_NOT_NULL(File1Buffer);
|
||||
char* File2Buffer = malloc(BufferSize);
|
||||
TEST_ASSERT_NOT_NULL(File2Buffer);
|
||||
|
||||
size_t File1Read = 0;
|
||||
size_t File2Read = 0;
|
||||
|
||||
do
|
||||
{
|
||||
File1Read = fread(File1Buffer, 1, BufferSize, File1Ptr);
|
||||
File2Read = fread(File2Buffer, 1, BufferSize, File2Ptr);
|
||||
TEST_ASSERT_EQUAL(File1Read, File2Read);
|
||||
if (File1Read > 0)
|
||||
{
|
||||
TEST_ASSERT_EQUAL_INT8_ARRAY(File1Buffer, File2Buffer, File1Read);
|
||||
}
|
||||
} while ((File1Read > 0) && (File2Read > 0));
|
||||
|
||||
free(File1Buffer);
|
||||
free(File2Buffer);
|
||||
|
||||
fclose(File1Ptr);
|
||||
fclose(File2Ptr);
|
||||
}
|
||||
|
||||
static void
|
||||
CheckBmp(char* Filename, const uint32_t* CorrectHeader,
|
||||
const uint8_t* FirstPixels, const uint8_t* LastPixels)
|
||||
{
|
||||
const int NrHeaderInts = 13;
|
||||
const int NrPixels = 8;
|
||||
const int BytesPerPixel = 3;
|
||||
char message[300];
|
||||
sprintf(message, "CheckBmp on filename: %s", Filename);
|
||||
FILE* FilePtr = NULL;
|
||||
uint32_t Header[NrHeaderInts];
|
||||
uint8_t PixelData[NrPixels * BytesPerPixel];
|
||||
int Result = 0;
|
||||
|
||||
FilePtr = fopen(Filename, "rb");
|
||||
TEST_ASSERT_NOT_NULL(FilePtr);
|
||||
|
||||
|
||||
fseek(FilePtr, 0x02, SEEK_SET);// skip 'BM' magic
|
||||
TEST_ASSERT_EQUAL_MESSAGE(
|
||||
NrHeaderInts,
|
||||
fread(&Header, sizeof(Header[0]), NrHeaderInts, FilePtr),
|
||||
message);
|
||||
TEST_ASSERT_EQUAL_HEX32_ARRAY_MESSAGE(
|
||||
CorrectHeader, Header, NrHeaderInts, message);
|
||||
|
||||
fseek(FilePtr,
|
||||
sizeof(BMP_MAGIC_t) + sizeof(BMP_FILE_t) + sizeof(BMP_INFO_t),
|
||||
SEEK_SET);
|
||||
Result = fread(PixelData, sizeof(PixelData[0]), NrPixels * BytesPerPixel,
|
||||
FilePtr);
|
||||
TEST_ASSERT_EQUAL_MESSAGE(NrPixels * BytesPerPixel, Result, message);
|
||||
TEST_ASSERT_EQUAL_HEX8_ARRAY_MESSAGE(
|
||||
FirstPixels, PixelData, NrPixels * BytesPerPixel, message);
|
||||
|
||||
fseek(FilePtr, -1 * NrPixels * BytesPerPixel, SEEK_END);
|
||||
Result = fread(PixelData, sizeof(PixelData[0]), NrPixels * BytesPerPixel,
|
||||
FilePtr);
|
||||
TEST_ASSERT_EQUAL_MESSAGE(NrPixels * BytesPerPixel, Result, message);
|
||||
TEST_ASSERT_EQUAL_HEX8_ARRAY_MESSAGE(
|
||||
LastPixels, PixelData, NrPixels * BytesPerPixel, message);
|
||||
|
||||
fclose(FilePtr);
|
||||
}
|
||||
|
||||
|
||||
static void test_GetSubstring(void)
|
||||
{
|
||||
const uint8_t TestData[] = {
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x02, 0x04, 0x08,
|
||||
0x10, 0x20, 0x40, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x01, 0x02, 0x04, 0x08,
|
||||
0x10, 0x20, 0x40, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02,
|
||||
0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20,
|
||||
0x40, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x01, 0x02, 0x04, 0x08,
|
||||
0x10, 0x20, 0x40, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x03, 0x06,
|
||||
0x0c, 0x18, 0x30, 0x60, 0xc0, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x02,
|
||||
0x04, 0x08, 0x10, 0x20, 0x40, 0x05, 0x0a, 0x14, 0x28, 0x50, 0xa0, 0x02,
|
||||
0x04, 0x08, 0x10, 0x20, 0x40, 0x05, 0x0a, 0x14, 0x28, 0x50, 0xa0, 0x06,
|
||||
0x0c, 0x18, 0x30, 0x60, 0xc0, 0x04, 0x08, 0x10, 0x20, 0x40, 0x0a, 0x14,
|
||||
0x28, 0x50, 0xa0, 0x05, 0x0a, 0x14, 0x28, 0x50, 0x0a, 0x14, 0x28, 0x50,
|
||||
0xa0, 0x0d, 0x1a, 0x34, 0x68, 0xd0, 0x14, 0x28, 0x50, 0xa0, 0x0a, 0x14,
|
||||
0x28, 0x50, 0x15, 0x2a, 0x54, 0xa8, 0x1a, 0x34, 0x68, 0xd0, 0x14, 0x28,
|
||||
0x50, 0x2a, 0x54, 0xa8, 0x35, 0x6a, 0xd4, 0x54, 0xa8, 0x6a, 0xd4
|
||||
};
|
||||
uint8_t Src = 0xd4;
|
||||
uint8_t SrcPos;
|
||||
uint8_t NrBits;
|
||||
uint8_t DestPos;
|
||||
int TestDataIndex = 0;
|
||||
|
||||
for (int j = 1; j < 8; j++)
|
||||
{
|
||||
for (int i = 0; i < 8; i++)
|
||||
{
|
||||
for (int k = 0; k < 8; k++)
|
||||
{
|
||||
if ((i + j <= 8) && (k + j <= 8))
|
||||
{
|
||||
SrcPos = i;
|
||||
NrBits = j;
|
||||
DestPos = k;
|
||||
char message[80];
|
||||
sprintf(message, "SrcPos: %i, NrBits: %i, DestPos: %i",
|
||||
SrcPos, NrBits, DestPos);
|
||||
TEST_ASSERT_EQUAL_HEX8_MESSAGE(
|
||||
TestData[TestDataIndex++],
|
||||
SteganoGetSubstring(
|
||||
Src, SrcPos, NrBits, DestPos),
|
||||
message);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void test_MultiplexTwoImages(void)
|
||||
{
|
||||
const char* File1 = "ImageTrabant.bmp";
|
||||
const char* File2 = "ImageRedFerrari.bmp";
|
||||
SteganoMultiplex(File1, File2);
|
||||
|
||||
uint32_t CorrectHeader0[] = { 0xc8a36, 0x1ac0280, 0x36, 0x28, 0x280,
|
||||
0x1ac, 0x180001, 0x0, 0xc8a00, 0xec4,
|
||||
0xec4, 0x0, 0x0 };
|
||||
uint8_t CorrectFirstBytes0[] = { 0x58, 0x5d, 0x5e, 0x4e, 0x53, 0x54,
|
||||
0x4e, 0x53, 0x54, 0x58, 0x5d, 0x5e,
|
||||
0x57, 0x5c, 0x5d, 0x4d, 0x52, 0x53,
|
||||
0x4d, 0x52, 0x55, 0x57, 0x5c, 0x5f };
|
||||
uint8_t CorrectLastBytes0[] = { 0x11, 0x58, 0x48, 0x11, 0x5a, 0x4a,
|
||||
0x13, 0x5b, 0x4e, 0x1b, 0x63, 0x56,
|
||||
0x22, 0x67, 0x5c, 0x17, 0x5c, 0x51,
|
||||
0x11, 0x54, 0x4b, 0x19, 0x5c, 0x53 };
|
||||
CheckBmp("mux_ImageTrabant.bmp_ImageRedFerrari.bmp_0.bmp", CorrectHeader0,
|
||||
CorrectFirstBytes0, CorrectLastBytes0);
|
||||
uint32_t CorrectHeader1[] = { 0xc8a36, 0x1ac0280, 0x36, 0x28, 0x280,
|
||||
0x1ac, 0x180001, 0x0, 0xc8a00, 0xec4,
|
||||
0xec4, 0x0, 0x1 };
|
||||
uint8_t CorrectFirstBytes1[] = { 0x59, 0x5d, 0x5f, 0x4f, 0x53, 0x55,
|
||||
0x4f, 0x53, 0x55, 0x59, 0x5d, 0x5f,
|
||||
0x57, 0x5d, 0x5d, 0x4d, 0x53, 0x53,
|
||||
0x4d, 0x53, 0x55, 0x57, 0x5d, 0x5f };
|
||||
uint8_t CorrectLastBytes1[] = { 0x10, 0x58, 0x48, 0x10, 0x5a, 0x4a,
|
||||
0x12, 0x5a, 0x4e, 0x1a, 0x62, 0x56,
|
||||
0x22, 0x66, 0x5c, 0x16, 0x5c, 0x50,
|
||||
0x10, 0x54, 0x4a, 0x18, 0x5c, 0x52 };
|
||||
CheckBmp("mux_ImageTrabant.bmp_ImageRedFerrari.bmp_1.bmp", CorrectHeader1,
|
||||
CorrectFirstBytes1, CorrectLastBytes1);
|
||||
uint32_t CorrectHeader4[] = { 0xc8a36, 0x1ac0280, 0x36, 0x28, 0x280,
|
||||
0x1ac, 0x180001, 0x0, 0xc8a00, 0xec4,
|
||||
0xec4, 0x0, 0x4 };
|
||||
uint8_t CorrectFirstBytes4[] = { 0x5d, 0x5d, 0x5d, 0x4d, 0x5d, 0x5d,
|
||||
0x4d, 0x5d, 0x5d, 0x5d, 0x5d, 0x5d,
|
||||
0x5d, 0x5d, 0x5d, 0x4d, 0x5d, 0x5d,
|
||||
0x4d, 0x5d, 0x5d, 0x5d, 0x5d, 0x5d };
|
||||
uint8_t CorrectLastBytes4[] = { 0x10, 0x50, 0x40, 0x10, 0x50, 0x40,
|
||||
0x10, 0x50, 0x40, 0x10, 0x60, 0x50,
|
||||
0x20, 0x60, 0x50, 0x10, 0x50, 0x50,
|
||||
0x10, 0x50, 0x40, 0x10, 0x50, 0x50 };
|
||||
CheckBmp("mux_ImageTrabant.bmp_ImageRedFerrari.bmp_4.bmp", CorrectHeader4,
|
||||
CorrectFirstBytes4, CorrectLastBytes4);
|
||||
uint32_t CorrectHeader7[] = { 0xc8a36, 0x1ac0280, 0x36, 0x28, 0x280,
|
||||
0x1ac, 0x180001, 0x0, 0xc8a00, 0xec4,
|
||||
0xec4, 0x0, 0x7 };
|
||||
uint8_t CorrectFirstBytes7[] = { 0x69, 0x69, 0x69, 0x69, 0x69, 0x69,
|
||||
0x69, 0x69, 0x69, 0x69, 0x69, 0x69,
|
||||
0x69, 0x69, 0x69, 0x69, 0x69, 0x69,
|
||||
0x69, 0x69, 0x69, 0x69, 0x69, 0x69 };
|
||||
uint8_t CorrectLastBytes7[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
|
||||
CheckBmp("mux_ImageTrabant.bmp_ImageRedFerrari.bmp_7.bmp", CorrectHeader7,
|
||||
CorrectFirstBytes7, CorrectLastBytes7);
|
||||
uint32_t CorrectHeader8[] = { 0xc8a36, 0x1ac0280, 0x36, 0x28, 0x280,
|
||||
0x1ac, 0x180001, 0x0, 0xc8a00, 0xec4,
|
||||
0xec4, 0x0, 0x8 };
|
||||
uint8_t CorrectFirstBytes8[] = { 0xd3, 0xd3, 0xd3, 0xd3, 0xd3, 0xd3,
|
||||
0xd3, 0xd3, 0xd3, 0xd3, 0xd3, 0xd3,
|
||||
0xd3, 0xd3, 0xd3, 0xd3, 0xd3, 0xd3,
|
||||
0xd3, 0xd3, 0xd3, 0xd3, 0xd3, 0xd3 };
|
||||
uint8_t CorrectLastBytes8[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
|
||||
CheckBmp("mux_ImageTrabant.bmp_ImageRedFerrari.bmp_8.bmp", CorrectHeader8,
|
||||
CorrectFirstBytes8, CorrectLastBytes8);
|
||||
}
|
||||
|
||||
static void test_DemultiplexTwoImages(void)
|
||||
{
|
||||
const char* File1 = "ImageTrabant.bmp";
|
||||
const char* File2 = "ImageRedFerrari.bmp";
|
||||
SteganoMultiplex(File1, File2);
|
||||
|
||||
SteganoDemultiplex(
|
||||
"mux_ImageTrabant.bmp_ImageRedFerrari.bmp_0.bmp",
|
||||
"demux_ImageTrabant_0.bmp", "demux_ImageRedFerrari_0.bmp");
|
||||
SteganoDemultiplex(
|
||||
"mux_ImageTrabant.bmp_ImageRedFerrari.bmp_1.bmp",
|
||||
"demux_ImageTrabant_1.bmp", "demux_ImageRedFerrari_1.bmp");
|
||||
SteganoDemultiplex(
|
||||
"mux_ImageTrabant.bmp_ImageRedFerrari.bmp_4.bmp",
|
||||
"demux_ImageTrabant_4.bmp", "demux_ImageRedFerrari_4.bmp");
|
||||
SteganoDemultiplex(
|
||||
"mux_ImageTrabant.bmp_ImageRedFerrari.bmp_7.bmp",
|
||||
"demux_ImageTrabant_7.bmp", "demux_ImageRedFerrari_7.bmp");
|
||||
SteganoDemultiplex(
|
||||
"mux_ImageTrabant.bmp_ImageRedFerrari.bmp_8.bmp",
|
||||
"demux_ImageTrabant_8.bmp", "demux_ImageRedFerrari_8.bmp");
|
||||
uint32_t CorrectHeader0[] = { 0xc8a36, 0x0, 0x36, 0x28, 0x280,
|
||||
0x1ac, 0x180001, 0x0, 0xc8a00, 0xec4,
|
||||
0xec4, 0x0, 0x0 };
|
||||
uint8_t CorrectFirstBytes0[] = { 0x50, 0x50, 0x50, 0x40, 0x50, 0x50,
|
||||
0x40, 0x50, 0x50, 0x50, 0x50, 0x50,
|
||||
0x50, 0x50, 0x50, 0x40, 0x50, 0x50,
|
||||
0x40, 0x50, 0x50, 0x50, 0x50, 0x50 };
|
||||
uint8_t CorrectLastBytes0[] = { 0x10, 0x50, 0x40, 0x10, 0x50, 0x40,
|
||||
0x10, 0x50, 0x40, 0x10, 0x60, 0x50,
|
||||
0x20, 0x60, 0x50, 0x10, 0x50, 0x50,
|
||||
0x10, 0x50, 0x40, 0x10, 0x50, 0x50 };
|
||||
CheckBmp("demux_ImageTrabant_4.bmp", CorrectHeader0, CorrectFirstBytes0,
|
||||
CorrectLastBytes0);
|
||||
uint32_t CorrectHeader1[] = { 0xc8a36, 0x0, 0x36, 0x28, 0x280,
|
||||
0x1ac, 0x180001, 0x0, 0xc8a00, 0xec4,
|
||||
0xec4, 0x0, 0x0 };
|
||||
uint8_t CorrectFirstBytes1[] = { 0xd2, 0xd2, 0xd2, 0xd2, 0xd2, 0xd2,
|
||||
0xd2, 0xd2, 0xd2, 0xd2, 0xd2, 0xd2,
|
||||
0xd2, 0xd2, 0xd2, 0xd2, 0xd2, 0xd2,
|
||||
0xd2, 0xd2, 0xd2, 0xd2, 0xd2, 0xd2 };
|
||||
uint8_t CorrectLastBytes1[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
|
||||
CheckBmp("demux_ImageRedFerrari_7.bmp", CorrectHeader1, CorrectFirstBytes1,
|
||||
CorrectLastBytes1);
|
||||
uint32_t CorrectHeader2[] = { 0xc8a36, 0x0, 0x36, 0x28, 0x280,
|
||||
0x1ac, 0x180001, 0x0, 0xc8a00, 0xec4,
|
||||
0xec4, 0x0, 0x0 };
|
||||
uint8_t CorrectFirstBytes2[] = { 0x58, 0x5c, 0x5e, 0x4e, 0x52, 0x54,
|
||||
0x4e, 0x52, 0x54, 0x58, 0x5c, 0x5e,
|
||||
0x56, 0x5c, 0x5c, 0x4c, 0x52, 0x52,
|
||||
0x4c, 0x52, 0x54, 0x56, 0x5c, 0x5e };
|
||||
uint8_t CorrectLastBytes2[] = { 0x10, 0x58, 0x48, 0x10, 0x5a, 0x4a,
|
||||
0x12, 0x5a, 0x4e, 0x1a, 0x62, 0x56,
|
||||
0x22, 0x66, 0x5c, 0x16, 0x5c, 0x50,
|
||||
0x10, 0x54, 0x4a, 0x18, 0x5c, 0x52 };
|
||||
CheckBmp("demux_ImageTrabant_1.bmp", CorrectHeader2, CorrectFirstBytes2,
|
||||
CorrectLastBytes2);
|
||||
uint32_t CorrectHeader3[] = { 0xc8a36, 0x0, 0x36, 0x28, 0x280,
|
||||
0x1ac, 0x180001, 0x0, 0xc8a00, 0xec4,
|
||||
0xec4, 0x0, 0x0 };
|
||||
uint8_t CorrectFirstBytes3[] = { 0xd0, 0xd0, 0xd0, 0xd0, 0xd0, 0xd0,
|
||||
0xd0, 0xd0, 0xd0, 0xd0, 0xd0, 0xd0,
|
||||
0xd0, 0xd0, 0xd0, 0xd0, 0xd0, 0xd0,
|
||||
0xd0, 0xd0, 0xd0, 0xd0, 0xd0, 0xd0 };
|
||||
uint8_t CorrectLastBytes3[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
|
||||
CheckBmp("demux_ImageRedFerrari_4.bmp", CorrectHeader3, CorrectFirstBytes3,
|
||||
CorrectLastBytes3);
|
||||
|
||||
Assert2FilesEqual("ImageTrabant.bmp", "demux_ImageTrabant_0.bmp");
|
||||
Assert2FilesEqual("ImageRedFerrari.bmp", "demux_ImageRedFerrari_8.bmp");
|
||||
}
|
||||
|
||||
static void test_MultiplexTextAndImage(void)
|
||||
{
|
||||
const char* File1 = "ImageCitroen2Cv.bmp";
|
||||
const char* File2 = "TextFontys.txt";
|
||||
SteganoMultiplexText(File1, File2);
|
||||
|
||||
uint32_t CorrectHeader0[] = { 0x56616, 0x115d, 0x36, 0x28, 0x1b8,
|
||||
0x10c, 0x180001, 0x0, 0x565e0, 0x0,
|
||||
0x0, 0x0, 0x0 };
|
||||
uint8_t CorrectFirstBytes0[] = { 0x74, 0x86, 0x8b, 0x98, 0xab, 0xae,
|
||||
0x61, 0x74, 0x76, 0x7c, 0x91, 0x8e,
|
||||
0x91, 0xa4, 0xa3, 0x88, 0x9e, 0x9a,
|
||||
0x93, 0xa8, 0xa3, 0x8c, 0xa3, 0x9c };
|
||||
uint8_t CorrectLastBytes0[] = { 0x3e, 0x5d, 0x36, 0x4a, 0x69, 0x42,
|
||||
0x39, 0x58, 0x33, 0x37, 0x56, 0x31,
|
||||
0x32, 0x50, 0x2d, 0x32, 0x50, 0x2d,
|
||||
0x30, 0x4e, 0x2b, 0x36, 0x54, 0x31 };
|
||||
CheckBmp("mux_ImageCitroen2Cv.bmp_TextFontys.txt.bmp", CorrectHeader0,
|
||||
CorrectFirstBytes0, CorrectLastBytes0);
|
||||
}
|
||||
|
||||
static void test_DemultiplexTextAndImage(void)
|
||||
{
|
||||
const char* File1 = "ImageCitroen2Cv.bmp";
|
||||
const char* File2 = "TextFontys.txt";
|
||||
SteganoMultiplexText(File1, File2);
|
||||
|
||||
SteganoDemultiplexText(
|
||||
"mux_ImageCitroen2Cv.bmp_TextFontys.txt.bmp",
|
||||
"demux_ImageCitroen2Cv.bmp", "demux_TextFontys.txt");
|
||||
uint32_t CorrectHeader0[] = { 0x56616, 0x0, 0x36, 0x28, 0x1b8,
|
||||
0x10c, 0x180001, 0x0, 0x565e0, 0x0,
|
||||
0x0, 0x0, 0x0 };
|
||||
uint8_t CorrectFirstBytes0[] = { 0x74, 0x86, 0x8a, 0x98, 0xaa, 0xae,
|
||||
0x60, 0x74, 0x76, 0x7c, 0x90, 0x8e,
|
||||
0x90, 0xa4, 0xa2, 0x88, 0x9e, 0x9a,
|
||||
0x92, 0xa8, 0xa2, 0x8c, 0xa2, 0x9c };
|
||||
uint8_t CorrectLastBytes0[] = { 0x3e, 0x5d, 0x36, 0x4a, 0x69, 0x42,
|
||||
0x39, 0x58, 0x33, 0x37, 0x56, 0x31,
|
||||
0x32, 0x50, 0x2d, 0x32, 0x50, 0x2d,
|
||||
0x30, 0x4e, 0x2b, 0x36, 0x54, 0x31 };
|
||||
CheckBmp("demux_ImageCitroen2Cv.bmp", CorrectHeader0, CorrectFirstBytes0,
|
||||
CorrectLastBytes0);
|
||||
uint32_t CorrectHeader1[] = { 0x6945202a, 0x6f68646e, 0x206e6576,
|
||||
0x0d2a2a2a, 0x440a0d0a, 0x65542065,
|
||||
0x696e6863, 0x65686373, 0x696e5520,
|
||||
0x73726576, 0x69657469, 0x69452074,
|
||||
0x6f68646e };
|
||||
uint8_t CorrectFirstBytes1[] = { 0x76, 0x65, 0x6e, 0x20, 0x65, 0x6e,
|
||||
0x20, 0x46, 0x6f, 0x6e, 0x74, 0x79,
|
||||
0x73, 0x20, 0x48, 0x6f, 0x67, 0x65,
|
||||
0x73, 0x63, 0x68, 0x6f, 0x6c, 0x65 };
|
||||
uint8_t CorrectLastBytes1[] = { 0x6e, 0x74, 0x79, 0x73, 0x2e, 0x6e,
|
||||
0x6c, 0x0d, 0x0a, 0x0d, 0x0a, 0x2d,
|
||||
0x2d, 0x20, 0x65, 0x69, 0x6e, 0x64,
|
||||
0x65, 0x20, 0x2d, 0x2d, 0x0d, 0x0a };
|
||||
CheckBmp("demux_TextFontys.txt", CorrectHeader1, CorrectFirstBytes1,
|
||||
CorrectLastBytes1);
|
||||
|
||||
Assert2FilesEqual("TextFontys.txt", "demux_TextFontys.txt");
|
||||
}
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
UnityBegin();
|
||||
|
||||
MY_RUN_TEST(test_GetSubstring);
|
||||
MY_RUN_TEST(test_MultiplexTwoImages);
|
||||
MY_RUN_TEST(test_DemultiplexTwoImages);
|
||||
MY_RUN_TEST(test_MultiplexTextAndImage);
|
||||
MY_RUN_TEST(test_DemultiplexTextAndImage);
|
||||
|
||||
return UnityEnd();
|
||||
}
|
||||
Reference in New Issue
Block a user