Example #1
0
/**
 * Read command line parameters and add test cases (-add option).
 */
int
AddTcase(int argc, char * argv[])
{
	int i, n, timeout = 20;
	char *c;
	char parameters[PARAMSIZE] = "";

	parameters[0] = '\0';
	for (i = 0; i < (argc - 2); i++) {
		if (strcmp(argv[i], "-timeout") == 0) {
			timeout = atoi(argv[i+1]);
			argv[i] = argv[i+1] = "";
		}
	}

	if (carrega_arquivo_tcase(&testSet, workingDir, testSessionName) == ERRO) {
	        return ERRO;
	}

	if (isInteractive) {
		if (tcase_ex_inter(workingDir, testSessionName, executableDir, executableFilename, parameters, SHELL) == ERRO) {
			return ERRO;;
		}
	} else {
		if (tcase_ex_bat(workingDir, testSessionName, executableDir, executableFilename, parameters) == ERRO) {
			return ERRO;
		}
	}

 	if (exec_from_ascii(executableDir, executableFilename, instrumentedExecutableFilename, parameters, workingDir, testSessionName, &(TREG(&testSet)), timeout,  enableTrace, SHELL, isInteractive) == ERRO ) {
		return ERRO;
	}
	TREG(&testSet).interativo = isInteractive;


	inic_to_buf(TREG(&testSet).param, sizeof(TREG(&testSet).param));
	inic_from_buf(parameters);
	for (c = from_buf(); c != NULL; c = from_buf()) {
		if (to_buf(c) == ERRO) {
			break;
		}
	}
	strcpy(TREG(&testSet).label, Label);
	if (insere_tcase(&testSet,  enableTrace) == ERRO) {
                return ERRO;
	}

	descarrega_arquivo_tcase(&testSet);
}
Example #2
0
// Converts string
std::string iconvpp::Converter::convert(const std::string& str)
{
	std::size_t from_size = str.size() + 1;

	// Max length of a character is 6 bytes in UTF-8.
	std::size_t to_size = 6 * from_size + 1;

	std::unique_ptr<char[]> from_buf(new char[from_size]);
	std::unique_ptr<char[]> to_buf(new char[to_size]);

	std::strcpy(from_buf.get(), str.c_str());

	// convert
	std::size_t from_size_temp = from_size - 1;
	std::size_t to_size_temp = to_size - 1;
	char* from_ptr = from_buf.get();
	char* to_ptr = to_buf.get();
	if (-1 == ::iconv(iconv_, &from_ptr, &from_size_temp, &to_ptr, &to_size_temp))
		throw iconvpp::Exception("Conversion failed.");
	
	*to_ptr = '\0';

	return std::string(to_buf.get());
}
Example #3
0
/**
 * Import test cases from POKE-TOOL.
 */
ImportPoke(int argc, char *argv[])
{
	FILE	*testCaseFile, *parametersFile;
	int	i, j, k, cont, TemPar;
	char 	*c;
	char XLabel[NOME_LENGTH+1];
	char parameters[PARAMSIZE] = "";

	if (carrega_arquivo_tcase(&testSet, workingDir, testSessionName) == ERRO) {
		return ERRO;
	}

	for (i = firstTestCase, cont = 0; i <= lastTestCase; i++) {
		// Try to import command line parameters for test case number i
		printf(testCaseInputDataImportFilename, "input%d.tes", i);
		strcpy(parameters, "");
		TemPar = FALSE;
		if (tem_arq(testCaseImportDir, testCaseInputDataImportFilename, "")) {
			parametersFile = abrearq(testCaseImportDir, testCaseInputDataImportFilename, "", 0);
			if (parametersFile != NULL) {
				posifim(parametersFile);
				k = ftell(parametersFile);
				if (k >= sizeof(parameters)) {
					msg("Invalid POKE-TOOL parameter file");
					fecharq(parametersFile);
				} else {
					posiciona(parametersFile, 0);
					fgets(parameters, (int) k, parametersFile);
				        k = strlen(parameters);
				        if (k > 0 && parameters[k-1] == '\n') {
						parameters[k-1] = '\0';
					}
					fecharq(parametersFile);
					TemPar = TRUE;
				}
			}
		}

		// Try to import test case number i
		sprintf(testCaseInputDataImportFilename, "tec%d.tes", i);
		if (tem_arq(testCaseImportDir, testCaseInputDataImportFilename, "")) {
			testCaseFile = abrearq(testCaseImportDir, testCaseInputDataImportFilename, "", 0);
			if (testCaseFile == NULL) {
				msg("Invalid POKE-TOOL test case");
				break;
			}
			fecharq(testCaseFile);
		}

		if (exec_from_ascii(executableDir, executableFilename, instrumentedExecutableFilename, parameters, workingDir, testSessionName, &(TREG(&testSet)), 120,  enableTrace, SHELL, isInteractive) == ERRO) {
			break;
		}
		TREG(&testSet).interativo = isInteractive;
		inic_to_buf(TREG(&testSet).param, sizeof(TREG(&testSet).param));
		inic_from_buf(parameters);
	   	for (c = from_buf(); c != NULL; c = from_buf()) {
			if (to_buf(c) == ERRO) {
				break;
			}
		}
		if (! isempty(Label)) {
			sprintf(XLabel, "%s%d", Label, i);
		} else {
			testCaseInputDataImportFilename[0] = '\0';
		}

		if (strlen(XLabel) <= LABELSIZE) {
			strcpy(TREG(&testSet).label, XLabel);
		} else {
			msg("Invalid label");
			TREG(&testSet).label[0] = '\0';
		}

		if (insere_tcase(&testSet,  enableTrace) == ERRO) {
                	break;
		}

		cont++;
		if (verbosityChar != '\0' && ! isspace(verbosityChar)) {
			fprintf(stdout, "%c", verbosityChar);
			fflush(stdout);
		}
	}

	printf("\n%d test cases imported from POKE-TOOL files\n", cont);

	descarrega_arquivo_tcase(&testSet);
	return OK;
}
Example #4
0
/**
 * Import test cases from plain text files.
 */
int
ImportAscii(int argc, char *argv[])
{
	FILE *testCaseFile, *parametersFile;
	int i, j, k, cont;
	char testCaseFilename[NOME_LENGTH+10];
	char parametersFilename[NOME_LENGTH+10];
	long t;
	char *c;
	char parameters[PARAMSIZE] = "";
	char XLabel[NOME_LENGTH+1];

	if (carrega_arquivo_tcase(&testSet, workingDir, testSessionName) == ERRO) {
		msg("Could not load test set");
		return ERRO;
	}

	if (strlen(testCaseInputDataImportFilename) > 0 || strlen(testCaseParametersImportFilename)) {
		msg("Invalid import filename");
	}

	for (i = firstTestCase, cont = 0; i <= lastTestCase; i++) {
		sprintf(parametersFilename, "%s%d", testCaseInputDataImportFilename, i);
		fprintf(stdout, "\nReading command line parameters from file %s", parametersFilename);
		strcpy(parameters, "");
		if (tem_arq(testCaseImportDir, parametersFilename, "")) {
		 	parametersFile = abrearq(testCaseImportDir, parametersFilename, "", 0);
			if (parametersFile == NULL) {
				fprintf(stdout, "\nError reading command line parameters");
			} else {
				posifim(parametersFile);
				t = ftell(parametersFile);
				posiciona(parametersFile, 0);
				if (t > sizeof(parameters)) {
					msg("Parameter too big");
				   	fclose(parametersFile);
				} else {
					fgets(parameters, (int) t, parametersFile);
					fclose(parametersFile);
					k = strlen(parameters);
					if (k > 0 && parameters[k-1] == '\n') {
						parameters[k-1] = '\0';
					}
				}
			}
		}

		sprintf(testCaseFilename, "%s%d", testCaseParametersImportFilename, i);
		printf("\nReading input data from file %s", testCaseFilename);
		if ( tem_arq(testCaseImportDir, testCaseFilename, "")) {
			testCaseFile = abrearq(testCaseImportDir, testCaseFilename, "", 0);
			if (testCaseFile == NULL) {
				fprintf(stdout, "\nError reading input data");
			}
			fecharq(testCaseFile);
			if (exec_from_ascii(executableDir, executableFilename, instrumentedExecutableFilename, parameters, workingDir, testSessionName, &(TREG(&testSet)), 120,  enableTrace, SHELL, isInteractive) == ERRO) {
				fprintf(stdout, "\nCould not run executable against input data and command line parameters");
			} else {
				TREG(&testSet).interativo = isInteractive;
				inic_to_buf(TREG(&testSet).param, sizeof(TREG(&testSet).param));
				inic_from_buf(parameters);
		   		for (c = from_buf(); c != NULL; c = from_buf())	{
					if (to_buf(c) == ERRO) {
						break;
					}
				}
		        	if (! isempty(Label)) {
					sprintf(XLabel, "%s%d", Label, i);
				} else {
        				XLabel[0] = '\0';
				}

			        if (strlen(XLabel) <= LABELSIZE) {
        				strcpy(TREG(&testSet).label, XLabel);
				} else {
     					msg("Invalid label");
					TREG(&testSet).label[0] = '\0';
				}

				if (insere_tcase(&testSet,  enableTrace) == ERRO) {
					fprintf(stderr, "\nCould not import the test case %d", i);
				} else {
					cont++;
			        	if (verbosityChar != '\0' && ! isspace(verbosityChar)) {       
						fprintf(stdout, "%c", verbosityChar);
				       		fflush(stdout);
					}
				}
			}
		}
	}

	fprintf(stdout, "\n%d test cases imported from ASCII files\n", cont);
	descarrega_arquivo_tcase(&testSet);

	return OK;
}
Example #5
0
/**
 * Import test cases from Proteum.
 */
int
ImportProteum(int argc, char *argv[])
{
	int i, k, cont = 0;
	int recordNumber;
	FILE *testCaseFile;
	char *c;
	HAND_TCASE importedTestSet;
	char XLabel[NOME_LENGTH+1];

	if (carrega_arquivo_tcase(&testSet, workingDir, testSessionName) == ERRO) {
		return ERRO;
	}

	if (carrega_arquivo_tcase(&importedTestSet, testCaseImportDir, testCaseInputDataImportFilename) == ERRO) {
		descarrega_arquivo_tcase(&testSet);
		return ERRO;
	}

	lastTestCase = MINI(lastTestCase, NTCASE(&importedTestSet));
	for (i = firstTestCase, cont = 0; i <= lastTestCase; i++) {
		recordNumber = ltofis_tcase(&importedTestSet, i);
		if (recordNumber == ERRO) {
			fprintf(stderr, "Error finding test case %d in the test set", i);
			continue;
		}

		if (le_tcase_reg(&importedTestSet, recordNumber) == ERRO) {
			fprintf(stderr, "Error importing test case %d (physical record %d)", i, recordNumber);
			continue;
		}

		testCaseFile = criarq(workingDir, testSessionName, SUFIXO_INPUT);
		if (testCaseFile == NULL) {
			fprintf(stderr, "Error creating temporary test case for imported test case %d", i);
			continue;
		}
		
		if (copy_file(TFILEIO(&importedTestSet), TREG(&testSet).apont_ent, TREG(&testSet).tamanho_ent, testCaseFile) == ERRO) {
			fprintf(stderr, "Error copying imported test case %i to temporary test case", i);
			continue;
		}
		fecharq(testCaseFile);

		if (exec_from_ascii(executableDir, executableFilename, instrumentedExecutableFilename, TREG(&importedTestSet).param, workingDir, testSessionName, &(TREG(&testSet)), 120,  enableTrace, NULL, TREG(&testSet).interativo) == ERRO) {
			continue;
		}
		TREG(&testSet).interativo = TREG(&importedTestSet).interativo;
		inic_to_buf(TREG(&testSet).param, sizeof(TREG(&testSet).param));
		inic_from_buf(TREG(&importedTestSet).param);
		for (c = from_buf(); c != NULL; c = from_buf()) {
			if (to_buf(c) == ERRO) {
				break;
			}
		}
   		
 		if (Label != NULL) {
			sprintf(XLabel, "%s%d", Label, i);
		} else {
	   		strcpy(XLabel, (char*) TREG(&importedTestSet).label);
		}

		if (strlen(XLabel) <= LABELSIZE) {
			strcpy(TREG(&testSet).label, XLabel);
		} else {
           		fprintf(stderr, "Invalid label for test case %d", i);
			TREG(&testSet).label[0] = '\0';
		}

		if (insere_tcase(&testSet, enableTrace) == ERRO) {
			return ERRO;
		} 

		if (verbosityChar != '\0') {	
			fprintf(stdout, "%c", verbosityChar);
			fflush(stdout);
		}
		cont++;
	}
	fprintf(stdout, "\n%d test cases imported from Proteum file", cont);

	descarrega_arquivo_tcase(&importedTestSet);
	descarrega_arquivo_tcase(&testSet);

	return OK;
}