// strtokWithQuotedStringsTest.cc 
// P. Conrad for CISC220, 06J    

// a version of strtok that allows delimiter to be ignored inside
//  a quoted string, e.g.

// "I, Robot",2004,Will Smith,120000000,144795350
//   or
// Will Smith,"Willard Christopher Smith, Jr.",09/25/1968,"Philadelphia, PA"


#include "strtokWithQuotedStrings.h"
#include <iostream>
using std::cout;
using std::cerr;
using std::endl;

#include "runTests.h"

int main(void)
{

  RunTests_C test;
    
  char testString1[] =
    "\"I, Robot\",2004,Will Smith,120000000,144795350";
  
  const char * const testResults1[] =
  {
    "I, Robot", // name of film
    "2004",      // year released
    "Will Smith",  // lead actor/actress
    "120000000",   // budget
    "144795350"    // latest US box office gross
  };
  
  const char * const result1FilmName 
    = strtokWithQuotedStrings(testString1,',','"');
  const char * const result1YearReleased 
    = strtokWithQuotedStrings(NULL,',','"');
  const char * const result1LeadActor
    = strtokWithQuotedStrings(NULL,',','"');
  const char * const result1Budget
    = strtokWithQuotedStrings(NULL,',','"');
  const char * const result1LatestBoxOfficeGross 
    = strtokWithQuotedStrings(NULL,',','"');

  test.assertEquals(result1FilmName,testResults1[0]);
  test.assertEquals(result1YearReleased,testResults1[1]);
  test.assertEquals(result1LeadActor,testResults1[2]);
  test.assertEquals(result1Budget,testResults1[3]);
  test.assertEquals(result1LatestBoxOfficeGross,testResults1[4]);

 
  char testString2[] = 
    "Will Smith,\"Willard Christopher Smith, Jr.\",09/25/1968,\"" 
    "Philadelphia, PA\"";
  

  const char * const testResults2[] =
  {
    
    "Will Smith", 
    "Willard Christopher Smith, Jr.",      // birth name
    "09/25/1968",  // date of birth
    "Philadelphia, PA"   // place of birth
  };
  
  const char * const result2ActorName 
    = strtokWithQuotedStrings(testString2,',','"');
  const char * const result2BirthName 
    = strtokWithQuotedStrings(NULL,',','"');
  const char * const result2DateOfBirth
    = strtokWithQuotedStrings(NULL,',','"');
  const char * const result2PlaceOfBirth
    = strtokWithQuotedStrings(NULL,',','"');

  test.assertEquals(result2ActorName,testResults2[0]);
  test.assertEquals(result2BirthName,testResults2[1]);
  test.assertEquals(result2DateOfBirth,testResults2[2]);
  test.assertEquals(result2PlaceOfBirth,testResults2[3]);

  test.print(cerr);
  test.finish();
}

