void test_getFileAddress_given_accessType_is_1_result_should_return_as_general_purpose_register_address(void)
{
  int fileAddress = 0x23;
  int accessType = BankRAM;
  BSR = 0x2;
  
  fileAddress = getFileAddress (fileAddress, accessType);
  
  TEST_ASSERT_EQUAL(0x223, fileAddress);
}
void test_movf_given_d_is_1_data_should_read_from_file_register_and_store_back_into_file_register(void)
{
  int fileAddress = 0x251;
  memory [fileAddress] = 0x78;
  int d = DIR_fileRegister, accessType = AccessRAM;
  
  movf (fileAddress, d, accessType);
  int dataMemoryAddr = getFileAddress (fileAddress, accessType);
  
  TEST_ASSERT_EQUAL_INT8(0x78, memory[dataMemoryAddr]); 
}
void test_incf_given_d_is_1_result_should_store_into_WREG(void)
{
  int fileAddress = 0x51;
  memory [fileAddress] = 0xFF;
  int d = DIR_fileRegister, accessType = AccessRAM;
  
  incf (fileAddress, d, accessType);
  int dataMemoryAddr = getFileAddress (fileAddress, accessType);
  
  TEST_ASSERT_EQUAL_INT8(0x00, memory[dataMemoryAddr]); 
}
void test_movf_given_d_is_0_data_should_read_from_file_register_and_store_into_WREG(void)
{
  int fileAddress = 0x51;
  memory [fileAddress] = 0x78;
  int d = DIR_WREG, accessType = AccessRAM;
  
  movf (fileAddress, d, accessType);
  int dataMemoryAddr = getFileAddress (fileAddress, accessType);
  
  TEST_ASSERT_EQUAL_INT8(0x78, WREG); 
}
void test_comf_given_d_is_1_result_should_store_into_file_register(void)
{
  int fileAddress = 0x49;
  memory [fileAddress] = 0x95;
  int d = DIR_fileRegister, accessType = AccessRAM;
  
  comf (fileAddress, d, accessType);
  int dataMemoryAddr = getFileAddress (fileAddress, accessType);
  
  TEST_ASSERT_EQUAL_INT8(0x6A, memory[dataMemoryAddr]); 
}
void test_comf_given_d_is_0_result_should_store_into_WREG(void)
{
  int fileAddress = 0x27;
  memory [fileAddress] = 0x13;
  int d = DIR_WREG, accessType = AccessRAM;
  
  comf (fileAddress, d, accessType);
  int dataMemoryAddr = getFileAddress (fileAddress, accessType);
  
  TEST_ASSERT_EQUAL_INT8(0xEC, WREG); 
  TEST_ASSERT_EQUAL(0x13, memory[dataMemoryAddr]); 
}
void test_clrf_given_accessType_is_1_should_clear_the_content_of_general_purpose_register(void)
{
  int fileAddress = 153;
  memory [fileAddress] = 0xC2;
  BSR = 0x1;
  int accessType = BankRAM;
  
  clrf (fileAddress, accessType);
  int dataMemoryAddr = getFileAddress (fileAddress, accessType);
  
  TEST_ASSERT_EQUAL(0, memory[dataMemoryAddr]); 
}
void test_writeByte_given_accessType_is_1_result_should_store_into_general_purpose_register(void)
{
  int value = 0x38;
  int fileAddress = 0x23;
  int accessType = BankRAM;
  BSR = 0x3;
  
  writeByte (fileAddress, accessType, value);
  int dataMemoryAddr = getFileAddress (fileAddress, accessType);
  
  TEST_ASSERT_EQUAL(0x38, memory[dataMemoryAddr]);
}
void test_movf_given_a_is_1_data_should_read_from_file_register_and_store_back_into_file_register_with_BSR(void)
{
  int fileAddress = 0x151;
  memory [fileAddress] = 0x11;
  BSR = 1;
  int d = DIR_fileRegister, accessType = BankRAM;
  
  movf (fileAddress, d, accessType);
  int dataMemoryAddr = getFileAddress (fileAddress, accessType);
  
  TEST_ASSERT_EQUAL_INT8(0x11, memory[dataMemoryAddr]); 
}
Esempio n. 10
0
void test_incf_given_a_is_1_result_should_store_into_general_purpose_register(void)
{
  int fileAddress = 0x251;
  memory [fileAddress] = 0x0F;
  BSR = 0x2;
  int d = DIR_fileRegister, accessType = BankRAM;
  
  incf (fileAddress, d, accessType);
  int dataMemoryAddr = getFileAddress (fileAddress, accessType);
  
  TEST_ASSERT_EQUAL_INT8(0x10, memory[dataMemoryAddr]); 
}
Esempio n. 11
0
void test_movwf_should_read_data_from_WREG_and_store_into_file_register(void)
{
  int fileAddress = 0x70;
  WREG = 0x39;
  int accessType = AccessRAM;
  
  movwf (fileAddress, accessType);
  int dataMemoryAddr = getFileAddress (fileAddress, accessType);
  
  
  TEST_ASSERT_EQUAL_INT8(0x39, memory[dataMemoryAddr]); 
}
Esempio n. 12
0
void test_movwf_given_a_is_1_should_read_data_from_WREG_and_store_into_file_register_with_BSR(void)
{
  int fileAddress = 0x570;
  WREG = 0x67;
  BSR = 5;
  int accessType = BankRAM;
  
  movwf (fileAddress, accessType);
  int dataMemoryAddr = getFileAddress (fileAddress, accessType);
  
  
  TEST_ASSERT_EQUAL_INT8(0x67, memory[dataMemoryAddr]); 
}
Esempio n. 13
0
void test_subwf_given_d_is_1_result_should_store_into_file_register(void)
{
  int fileAddress = 0x34;
  memory [fileAddress] = 0x18;
  WREG  = 0x19;
  int d = DIR_fileRegister, accessType = AccessRAM;
  
  subwf (fileAddress, d, accessType);
  int dataMemoryAddr = getFileAddress (fileAddress, accessType);
  
  TEST_ASSERT_EQUAL_INT8(0x19, WREG);
  TEST_ASSERT_EQUAL_INT8(0xFF, memory[dataMemoryAddr]); 
}
Esempio n. 14
0
void test_subwf_given_d_is_0_result_should_store_into_WREG(void)
{
  int fileAddress = 0x25;
  memory [fileAddress] = 0x04;
  WREG  = 0x01;
  int d = DIR_WREG, accessType = AccessRAM;
  
  subwf (fileAddress, d, accessType);
  int dataMemoryAddr = getFileAddress (fileAddress, accessType);
  
  TEST_ASSERT_EQUAL_INT8(0x03, WREG);
  TEST_ASSERT_EQUAL_INT8(0x04, memory[dataMemoryAddr]); 
}
Esempio n. 15
0
void test_xorwf_given_d_is_1_result_should_store_into_file_register(void)
{
  int fileAddress = 0x27;
  memory [fileAddress] = 0xF1;
  WREG  = 0x14;
  int d = DIR_fileRegister, accessType = AccessRAM;
  
  xorwf (fileAddress, d, accessType);
  int dataMemoryAddr = getFileAddress (fileAddress, accessType);
  
  TEST_ASSERT_EQUAL(0x14, WREG);
  TEST_ASSERT_EQUAL(0xE5, memory[dataMemoryAddr]);
}
Esempio n. 16
0
void test_xorwf_given_d_is_0_result_should_store_into_WREG(void)
{
  int fileAddress = 0x25;
  memory [fileAddress] = 0xC2;
  WREG  = 0x17;
  int d = DIR_WREG, accessType = AccessRAM;
  
  xorwf (fileAddress, d, accessType);
  int dataMemoryAddr = getFileAddress (fileAddress, accessType);
  
  TEST_ASSERT_EQUAL(0xD5, WREG);
  TEST_ASSERT_EQUAL(0xC2, memory[dataMemoryAddr]); 
}
Esempio n. 17
0
void test_writeToFileRegister_given_d_is_1_result_should_store_into_file_register(void)
{
  int value = 0xF3;
  int fileAddress = 0xE8;
  int d = DIR_fileRegister;
  int accessType = BankRAM;
  BSR = 4;
  
  writeToFileRegister(fileAddress, d, accessType, value);
  fileAddress = getFileAddress (fileAddress, accessType);
  
  TEST_ASSERT_EQUAL(0xF3, memory[fileAddress]);  
}
Esempio n. 18
0
void test_subwf_given_accessType_is_1_result_should_store_into_general_purpose_register(void)
{
  int fileAddress = 0x423;
  memory [fileAddress] = 0x34;
  WREG  = 0x22;
  BSR = 0x4;
  int d = DIR_fileRegister, accessType = BankRAM;

  subwf (fileAddress, d, accessType);
  int dataMemoryAddr = getFileAddress (fileAddress, accessType);
  
  TEST_ASSERT_EQUAL_INT8(0x22, WREG);
  TEST_ASSERT_EQUAL_INT8(0x12, memory[dataMemoryAddr]); 
}
Esempio n. 19
0
void test_addwfc_given_accessType_is_0_result_should_store_into_access_bank(void)
{
  int fileAddress = 0x12;
  memory [fileAddress] = 0xC2;
  WREG  = 0x17;
  STATUS = 0x1;
  int d = DIR_fileRegister, accessType = AccessRAM;
  
  addwfc (fileAddress, d, accessType);
  int dataMemoryAddr = getFileAddress (fileAddress, accessType);
  
  TEST_ASSERT_EQUAL(0x17, WREG); 
  TEST_ASSERT_EQUAL(0xDA, memory[dataMemoryAddr]); 
}
Esempio n. 20
0
void test_subwfb_given_d_is_1_result_should_store_into_file_register(void)
{
  int fileAddress = 0x25;
  memory [fileAddress] = 0x17;
  WREG  = 0x63;
  int d = DIR_fileRegister, accessType = AccessRAM;
  STATUS = 0x1;
  
  subwfb(fileAddress, d, accessType);
  int dataMemoryAddr = getFileAddress (fileAddress, accessType);
  
  TEST_ASSERT_EQUAL_INT8(0x63, WREG);
  TEST_ASSERT_EQUAL_INT8(0xB4, memory[dataMemoryAddr]); 
}
Esempio n. 21
0
void test_xorwf_given_accessType_is_1_result_should_store_into_general_purpose_register(void)
{
  int fileAddress = 0x327;
  memory [fileAddress] = 0xC2;
  WREG  = 0x17;
  BSR = 0x3;
  int d = DIR_fileRegister, accessType = BankRAM;
  
  xorwf (fileAddress, d, accessType);
  int dataMemoryAddr = getFileAddress (fileAddress, accessType);
  
  TEST_ASSERT_EQUAL(0x17, WREG); 
  TEST_ASSERT_EQUAL(0xD5, memory[dataMemoryAddr]); 
}
Esempio n. 22
0
void test_addwf_given_d_is_0_result_should_store_into_WREG(void)
{
  int fileAddress = 0x23;
  memory[fileAddress] = 0xEE;
  WREG = 0x12;
  int d = DIR_WREG, accessType = AccessRAM;
  
  addwf (fileAddress, d, accessType);
  int dataMemoryAddr = getFileAddress (fileAddress, accessType);
    
    
  TEST_ASSERT_EQUAL_INT8(0x00, WREG);
  TEST_ASSERT_EQUAL(0xEE, memory[dataMemoryAddr]);
  TEST_ASSERT_EQUAL(0x0F, STATUS);  
}
Esempio n. 23
0
void test_addwfc_given_d_is_1_result_should_store_into_file_register(void)
{
  int fileAddress = 0x312;
  memory [fileAddress] = 0xC2;
  WREG  = 0x17;
  BSR = 0x3;
  STATUS = 0x0;
  int d = DIR_fileRegister, accessType = BankRAM;
  
  addwfc (fileAddress, d, accessType);
  int dataMemoryAddr = getFileAddress (fileAddress, accessType);

  
  TEST_ASSERT_EQUAL(0x17, WREG); 
  TEST_ASSERT_EQUAL(0xD9, memory[dataMemoryAddr]); 
}
int main(int argc, char **argv) {

  int link = 1, i;
   /* directorul de la cere se pleaca initial */
  char *directory = (char *)malloc(MAXLEN* sizeof(char));
  char *filePath = (char *)malloc(MAXLEN * sizeof(char));
  char *linkPrimit = (char *)malloc(MAXLEN * sizeof(char));
  char *linkScriere = (char *)malloc(MAXLEN * sizeof(char));
  char * addres = (char *)malloc(MAXLEN * sizeof(char));
  char * fileLog = (char *)malloc(MAXLEN * sizeof(char));
  char *argL = (char *)malloc(MAXLEN * sizeof(char));

  memset(fileLog,0,MAXLEN);
  memset(directory,0,MAXLEN);
  memset(filePath,0,MAXLEN);
  memset(addres,0,MAXLEN);
  memset(linkPrimit,0,MAXLEN);
  memset(linkScriere,0,MAXLEN);
  memset(argL,0,MAXLEN);

  /* se concateneaza totate argumentele din linia de comanda */
   for (i = 1; i< argc ;i ++)
    strcat(argL,argv[i]);

  /* verificare ce argumente sunt active */
  if(strstr(argL,"-r") > 0){ 
    activR = 1;
  }
  if(strstr(argL,"-e") > 0){
    activE = 1;
  }
  if(strstr(argL,"-o") > 0){
    activO = 1;
  }
  /* nu sunt argumente in linia de comanda */
  if(argc == 2){
    link = 1;
  }
  /* un singur argument */
  if(argc == 3){
    link = 2;
  }
  /* 2 argumente */
  if(argc == 4){
    link = 3;
    if(activO == 1)
      sprintf(fileLog,"%s",argv[2]);
  }
  /* toate argumentele */
  if(argc == 6){
    link = 5;
    sprintf(fileLog,"%s",argv[4]);
  }
  if(activO == 1)
    fExit = fopen(fileLog,"w");

  if(argc == 5){
    if(activO == 1){
      fprintf(fExit, "Eroare numar de argumente incorecte\n");
      exit(-1);
    }
    else{
      fprintf(stderr, "Eroare numar de argumente incorecte\n");
      exit(-1);
    }
  }
  
  
  /* trimit o singura data cand nu am argumente in linia de comanda*/
  
  getFileAddress(argv[link],linkPrimit,filePath,directory);
  sprintf(linkScriere,"%s%s",directory,filePath);

  /* se creaza directorul de start din link-ul primit ca parametru */
  getAdress(linkPrimit,addres);
  mkdir(addres,S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH);
  mkdir(directory,S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH);

 
  /* se apeleaza functia pentru a descarca paginile cerute */
  linkPages(argv[link],linkPrimit,linkScriere,directory,1,0);

  if(activO == 1)
    fclose(fExit);
  free(directory);
  free(linkPrimit);
  free(linkScriere);
  free(filePath);
  free(addres);
  free(argL);
  free(fileLog);
}
/* functia parcurge paginile, apeleaza recursiv si descarca in functie
 de parametri dati in linia de comanda */
void linkPages(char * original, char * argument,char * filePath, char * directory,int rec, int s){
  
  /* conditia de oprire */
  if (rec > 5)
    return;

  int sockfd;
  int port = SMTP_PORT;
  int rezult, i = 0, len = 0;

  struct sockaddr_in servaddr;
  struct hostent * host;

  /* declarare constante */
  char server_ip[10];
  char sendbuf[MAXLEN]; 
  char recvbuf[MAXLEN];

  char * addres = (char *)malloc(MAXLEN * sizeof(char));
  char * ipAd = (char *)malloc(MAXLEN * sizeof(char));
  char *fileApel = (char *)malloc(MAXLEN * sizeof(char));
  char *linkPrimit = (char *)malloc(MAXLEN * sizeof(char));
  char *fileNext = (char *)malloc(MAXLEN * sizeof(char));
  char *m = (char *)malloc(MAXLEN * sizeof(char));
  char *p = (char *)malloc(MAXLEN * sizeof(char));
  char *getCom = (char *)malloc(MAXLEN * sizeof(char));
  char **d = (char **)malloc(MAXLEN * sizeof(char));

  /* setare pe 0 pentru a evita erorile */
  memset(getCom,0,MAXLEN);
  memset(p,0,MAXLEN);
  memset(addres,0,MAXLEN);
  memset(ipAd,0,MAXLEN);
  memset(fileApel,0,MAXLEN);
  memset(fileNext,0,MAXLEN);
  memset(linkPrimit,0,MAXLEN);
  memset(m,0,MAXLEN);

  /* calculare adresa primita ca parametru */
  getAdress(argument,addres);
  host = gethostbyname(addres);
  /* calculare adresa IP */
  sprintf(ipAd,"%s",inet_ntoa(*(struct in_addr*)host->h_addr_list[0]));

  strcpy(server_ip, ipAd);

  if ( (sockfd = socket(AF_INET, SOCK_STREAM, 0)) < 0 ){
    if(activO == 1){
      fprintf(fExit,"Eroare la creare socket.\n");
    }
    else
      fprintf(stderr,"Eroare la creare socket.\n");
    exit(-1);
  }  

  /* formarea adresei serverului */
  memset(&servaddr, 0, sizeof(servaddr));
  servaddr.sin_family = AF_INET;
  servaddr.sin_port = htons(port);

  if (inet_aton(server_ip, &servaddr.sin_addr) <= 0 ) {
    if(activO == 1){
      fprintf(fExit, "Adresa IP invalida.\n");
    }
    else{
      fprintf(stderr, "Adresa IP invalida.\n");
    }
    exit(-1);
  }
    
  /*  conectare la server  */
  if (connect(sockfd, (struct sockaddr *) &servaddr, sizeof(servaddr)) < 0 ) {
    if(activO == 1){
      fprintf(fExit, "Eroare la conectare\n");
    }
    else{
      fprintf(stderr, "Eroare la conectare\n");
    }
    exit(-1);
  }
  /* trimitere comanda la server */
  sprintf(getCom,"GET %s HTTP/1.0 \n\n",original);

  FILE * f = fopen(filePath,"wb");

  send_command(sockfd,getCom);
 
  i = 0;
  /* se elimina antetul din pagina primita */
  while((len = Readline(sockfd,recvbuf,MAXLEN-1)) > 0){
    i++;
    if(len <= 2)
      break;
      memset(recvbuf, 0, MAXLEN);
  }

  /* daca a fost trimis link de descarcare */
  if (s == 1){
    while((len = recv(sockfd, recvbuf, MAXLEN, 0)) > 0) {
      fwrite(recvbuf, sizeof(char), len, f);
      memset(recvbuf, 0, MAXLEN);
    }
  }
  /* altfel se verifica paginile .html si de scriu in fisier */
  else{
    while(Readline(sockfd, recvbuf, MAXLEN) > 0){
      /* verifica daca linia curecta contine  */
      if(vefiricaLink(recvbuf) == 1){
        extractLink(recvbuf,p);

        if(strcmp(p,"") != 0){
          sprintf(m,"%s%s",argument,p);
          memset(directory,0,MAXLEN);
          d = getFileAddress(m,linkPrimit,fileNext,directory);
          sprintf(fileApel,"%s%s",directory,fileNext);
          
          /* numai pentru recursivitate */
          if (activR == 1 && strstr(p,".html") > 0){
            i = 0; 
            /* creeaza ierarhia de directoare */
            while(d[i] != NULL){
              mkdir(d[i],S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH);
              i ++;
            } 
            /* verifica daca fisierul exista */
            rezult = access(fileApel,F_OK);
            /* daca nu exista se apeleaza recursiv pentru link-urile gasite */
            if(rezult != 0 && rec <= 5 )
              linkPages(m,linkPrimit,fileApel,directory,rec + 1,0);
            }
            /* daca este activ -e se apeleaza recursiv pentru a se descarca */
            if(activE == 1 && strstr(p,".html") <= 0){
              i = 0;
              /* creeaza ierarhia de directoare */ 
              while(d[i] != NULL){
                mkdir(d[i],S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH);
                i ++;
              } 
              /* verifica daca fisierul exista */
              rezult = access(fileApel,F_OK);
              /* se apeleaza recursiv cu s = 1 pentru a intra pe coditia
                 pentru descarcare */
              if(rezult != 0 ){
                linkPages(m,linkPrimit,fileApel,directory,1,1);
              }
            } 
          }
      }
    /* scrie paginile in fisier */
    for(i = 0; i < strlen(recvbuf) ;i ++)
      fwrite(&recvbuf[i],sizeof(char),1,f);
  }
}
  free(addres);
  free(ipAd);
  free(getCom);
  free(m);
  free(linkPrimit);
  free(fileApel);
  free(p);
  free(fileNext);

  fclose(f);
  close(sockfd);
}