//----------------------------------------------------------------------------
//
//  ise_test_7.cpp
//
//  Authors: Joe Jarchow, Geoffrey Griffith, Joseph Kadhim, Shinya Daigaku
//           Andrew Pouzeshi
//
//  Sponsor: Tom Lookabaugh, Assistant Professor of Computer Science
//           University of Colorado
//
//  Senior Project: Team ISE (Image Selective Encryption)
//----------------------------------------------------------------------------


// This file is designed to test the ISE production code with test7.sh

#include <stdlib.h>     
#include <iostream>
#include <fstream> 
#include <string>
#include "rijndael-api-fst.h"
#include "ise.h"

using namespace std;

int main(int argc, char * argv[])
{
    /* Set_Input_File_Name Function with Non-Valid File (non .jpg file) */

    size_t length = 0;
    int err = 0;
    char MyKey [] = "enterthekey";

    /* Call the constructor with only the key */
    jpeg_ise encrypt_test(MyKey);

    /* Test the "set_input_file_name()" function by looping through all possible 1&2 char extensions */
    /* only output acceptable extensions */
    length = 3;
    int first_char = 2;
    int second_char = 3;
    int third_char = 4;

    /* test 1 char extensions */
    char * test_input_file_name;  
    test_input_file_name = new char[length + 1];
    strcpy (test_input_file_name,"a.a");
    for (int i = 0; i < 255; i++)
    {
        test_input_file_name[first_char] = (char)i;
        err = encrypt_test.set_input_file_name(test_input_file_name);
        if (err == 0) 
        {
	    test_input_file_name[0] = '*';
            cout << "Test 7: valid extension detected:" << test_input_file_name << endl;
        }
    }
    delete [] test_input_file_name;

    /* test 2 char extensions */
    length = 4; 
    test_input_file_name = new char[length + 1];
    strcpy (test_input_file_name,"a.aa");
    for (unsigned int i = 0; i < 255; i++)
    {
      test_input_file_name[first_char] = (char)i;
      for (unsigned int j = 0; j < 255; j++)
      {
        test_input_file_name[second_char] = (char)j;
        err = encrypt_test.set_input_file_name(test_input_file_name);
        if (err == 0) 
        {
	    test_input_file_name[0] = '*';
            cout << "Test 7: valid extension detected:" << test_input_file_name << endl;
        }
      }
    }
    delete [] test_input_file_name;

    /* test 3 char extensions */
    length = 5; 
    test_input_file_name = new char[length + 1];
    strcpy (test_input_file_name,"a.aaa");
    for (unsigned int i = 0; i < 255; i++)
    {
      test_input_file_name[first_char] = (char)i;
      for (unsigned int j = 0; j < 255; j++)
      {
        test_input_file_name[second_char] = (char)j;
	for (unsigned int k = 0; k < 255; k++)
	{
	  test_input_file_name[third_char] = (char)k;
	  err = encrypt_test.set_input_file_name(test_input_file_name);
	  if (err == 0) 
          {
	    test_input_file_name[0] = '*';
            cout << "Test 7: valid extension detected:" << test_input_file_name << endl;
          }
	}
      }
    }
    delete [] test_input_file_name;

    return 0;
}
