TEST_F(TestFetchDocumentCallback, Basics)
{
    // Define schema
    rapidjson::Document schemaDocument;
    RapidJsonAdapter schemaDocumentAdapter(schemaDocument);
    schemaDocument.SetObject();
    schemaDocument.AddMember("$ref", "test#/", allocator);

    // Parse schema document
    Schema schema;
    SchemaParser schemaParser;
    schemaParser.populateSchema(schemaDocumentAdapter, schema,
            boost::make_optional<FetchDocumentFunction>(fetchDocument));

    // Test resulting schema with a valid document
    rapidjson::Document validDocument;
    validDocument.SetObject();
    validDocument.AddMember("test", "valid", allocator);
    Validator validator;
    EXPECT_TRUE(validator.validate(schema, RapidJsonAdapter(validDocument), NULL));

    // Test resulting schema with an invalid document
    rapidjson::Document invalidDocument;
    invalidDocument.SetObject();
    invalidDocument.AddMember("test", 123, allocator);
    EXPECT_FALSE(validator.validate(schema, RapidJsonAdapter(invalidDocument), NULL));
}
Exemplo n.º 2
0
bool OrganiseFormat::IsValid() const {
    int pos = 0;
    QString format_copy(format_);

    Validator v;
    return v.validate(format_copy, pos) == QValidator::Acceptable;
}
Exemplo n.º 3
0
string getMoveChoice()
{
	string input;
	Validator myVal;

	cout << endl << "Enter the position of your move. eg: x,y" << endl;

	if (myVal.validate(&input)) {

		// validate x,y input

		//if (regex_match(input, regex{ "/\d\,\d/g" }))
		//{
		//	cout << "match";
		//}
		//else {
		//	cout << "not match";
		//}

		return input;
	}
	else {
		cout << "The input " << input << " is not valid" << endl;
		_getch();
		getMoveChoice();
	}
}
Exemplo n.º 4
0
int 
main(int argc, char *argv ) 
{
    char *buf = NULL;
    asprintf(&buf, "%d", BLAH );
    printf("%s\n", buf );
    Validator *tmp = NewValidator(2,4);
    int result = 0;
    if( tmp->validate( tmp , &result ) ) {
        printf("Was good\n");
    }  else {
        printf("was bad: %d\n", result );
    }
    tmp = NewValidator(2,6);
    if( tmp->validate( tmp , &result ) ) {
        printf("Was good\n");
    }  else {
        printf("was bad: %d\n", result );
    }
    result = 0;

    tmp = NewValidator2( NewValidator(4,6) );

    if( tmp->validate( tmp , &result ) ) {
        printf("Was good\n");
    }  else {
        printf("was bad: %d\n", result );
    }

    result = 0;
    (tmp = OddValidator( NewValidator2( NewValidator(-1,1)  )  )   )->validate( tmp, &result );

    /**
     * Better would be 
     *
     * validator( &result, obj, 3 , OddValidator, NewValidator2, NewValidator1 );
     *
     *
     *
     */

    if( result == 0 ) {
        printf("Was good\n");
    } else {
        printf("was bad: %d\n", result );
    }
}
Exemplo n.º 5
0
TEST(ValidatorTest, SmallIntNegative) {
  for (uint8_t i = 0; i <= 5; ++i) {
    std::string value;
    value.push_back(0x3a + i);

    Validator validator;
    ASSERT_TRUE(validator.validate(value.c_str(), value.size()));
  }
}
Exemplo n.º 6
0
bool turnChoice()
{
	string input;
	Validator myVal;
	cout << "Would you like to go first? (y/n)" << endl;
	if (myVal.validate(&input)) {
		if (input == "n" || input == "N")
		{
			return false;
		}
		else if (input == "Y" || input == "y")
		{
			return true;
		}
		else {
			main();
		}
	}
	else {
		cout << "The input " << input << " is not valid" << endl;
		_getch();
		main();
	}
}
Exemplo n.º 7
0
TEST(ValidatorTest, ArrayTwoBytesTooFewMembers2) {
  std::string const value("\x03\x06\x00\x18\x18", 5);

  Validator validator;
  ASSERT_VELOCYPACK_EXCEPTION(validator.validate(value.c_str(), value.size()), Exception::ValidatorInvalidLength);
}
Exemplo n.º 8
0
TEST(ValidatorTest, ArrayTwoBytesMultipleMembers) {
  std::string const value("\x03\x06\x00\x18\x18\x18", 6);

  Validator validator;
  ASSERT_TRUE(validator.validate(value.c_str(), value.size()));
}
Exemplo n.º 9
0
TEST(ValidatorTest, CustomOneByteFD) {
  std::string const value("\xfd\x01\x00\x00\x00\x00\x00\x00\x00\xff", 10);

  Validator validator;
  ASSERT_TRUE(validator.validate(value.c_str(), value.size()));
}
Exemplo n.º 10
0
TEST(ValidatorTest, CustomEightBytes) {
  std::string const value("\xf3\xff\xff\xff\xff\xff\xff\xff\xff", 9);

  Validator validator;
  ASSERT_TRUE(validator.validate(value.c_str(), value.size()));
}
Exemplo n.º 11
0
TEST(ValidatorTest, ArrayOneByteIndexedIndexOutOfBounds3) {
  std::string const value("\x06\x05\x01\x18\x00", 5);

  Validator validator;
  ASSERT_VELOCYPACK_EXCEPTION(validator.validate(value.c_str(), value.size()), Exception::ValidatorInvalidLength);
}
Exemplo n.º 12
0
TEST(ValidatorTest, ArrayOneByteIndexedTooShort2) {
  std::string const value("\x06\x05\x01", 3);

  Validator validator;
  ASSERT_VELOCYPACK_EXCEPTION(validator.validate(value.c_str(), value.size()), Exception::ValidatorInvalidLength);
}
Exemplo n.º 13
0
TEST(ValidatorTest, ArrayOneByteTooShortBytesize) {
  std::string const value("\x02\x05", 2);

  Validator validator;
  ASSERT_VELOCYPACK_EXCEPTION(validator.validate(value.c_str(), value.size()), Exception::ValidatorInvalidLength);
}
Exemplo n.º 14
0
TEST(ValidatorTest, ArrayOneByte) {
  std::string const value("\x02\x03\x18", 3);

  Validator validator;
  ASSERT_TRUE(validator.validate(value.c_str(), value.size()));
}
Exemplo n.º 15
0
TEST(ValidatorTest, EmptyArrayWithExtra) {
  std::string const value("\x01\x02", 2);

  Validator validator;
  ASSERT_VELOCYPACK_EXCEPTION(validator.validate(value.c_str(), value.size()), Exception::ValidatorInvalidLength);
}
Exemplo n.º 16
0
TEST(ValidatorTest, EmptyArray) {
  std::string const value("\x01", 1);

  Validator validator;
  ASSERT_TRUE(validator.validate(value.c_str(), value.size()));
}
Exemplo n.º 17
0
TEST(ValidatorTest, BCD) {
  std::string const value("\xd0", 1);

  Validator validator;
  ASSERT_VELOCYPACK_EXCEPTION(validator.validate(value.c_str(), value.size()), Exception::NotImplemented);
}
Exemplo n.º 18
0
TEST(ValidatorTest, CustomOneByteFDWithExtra) {
  std::string const value("\xfd\x01\x00\x00\x00\x00\x00\x00\x00\xff\x41", 11);

  Validator validator;
  ASSERT_VELOCYPACK_EXCEPTION(validator.validate(value.c_str(), value.size()), Exception::ValidatorInvalidLength);
}
Exemplo n.º 19
0
TEST(ValidatorTest, CustomOneByteFDTooShort2) {
  std::string const value("\xfd\x01\x00", 3);

  Validator validator;
  ASSERT_VELOCYPACK_EXCEPTION(validator.validate(value.c_str(), value.size()), Exception::ValidatorInvalidLength);
}
Exemplo n.º 20
0
TEST(ValidatorTest, ArrayTwoBytesMultipleMembersDifferentSizes) {
  std::string const value("\x03\x05\x18\x28\x00", 5);

  Validator validator;
  ASSERT_VELOCYPACK_EXCEPTION(validator.validate(value.c_str(), value.size()), Exception::ValidatorInvalidLength);
}
Exemplo n.º 21
0
TEST(ValidatorTest, ArrayOneByteIndexed) {
  std::string const value("\x06\x05\x01\x18\x03", 5);

  Validator validator;
  ASSERT_TRUE(validator.validate(value.c_str(), value.size()));
}
Exemplo n.º 22
0
TEST(ValidatorTest, ArrayOneByteMultipleMembers) {
  std::string const value("\x02\x05\x18\x18\x18", 5);

  Validator validator;
  ASSERT_TRUE(validator.validate(value.c_str(), value.size()));
}
Exemplo n.º 23
0
TEST(ValidatorTest, TrueValueWithExtra) {
  std::string const value("\x1a\x41", 2);

  Validator validator;
  ASSERT_VELOCYPACK_EXCEPTION(validator.validate(value.c_str(), value.size()), Exception::ValidatorInvalidLength);
}
Exemplo n.º 24
0
TEST(ValidatorTest, ArrayOneByteTooFewMembers1) {
  std::string const value("\x02\x05\x18", 3);

  Validator validator;
  ASSERT_VELOCYPACK_EXCEPTION(validator.validate(value.c_str(), value.size()), Exception::ValidatorInvalidLength);
}
Exemplo n.º 25
0
TEST(ValidatorTest, CustomEightBytesTooShort) {
  std::string const value("\xf3", 1);

  Validator validator;
  ASSERT_VELOCYPACK_EXCEPTION(validator.validate(value.c_str(), value.size()), Exception::ValidatorInvalidLength);
}
Exemplo n.º 26
0
TEST(ValidatorTest, TrueValue) {
  std::string const value("\x1a", 1);

  Validator validator;
  ASSERT_TRUE(validator.validate(value.c_str(), value.size()));
}
Exemplo n.º 27
0
bool QEbuMainWindow::doOpen()
{
    // Close before open!
    if (!doClose())
        return false;

    QString filename = QFileDialog::getOpenFileName(this, tr("Open Metadata File"),
                                            QDir::homePath(),
                                            tr("XML Files (*.xml)"), 0);
    if (filename.isEmpty()) {
        // User pressed "Cancel"
        return false;
    }

    QFile inputFile(filename);
    if (!inputFile.open(QFile::ReadOnly)) {
        QMessageBox openWarning(QMessageBox::Warning, tr("QEbu Parser"),
                                tr("Input file cannot be opened"),
                                QMessageBox::Ok, this);
        openWarning.setDetailedText(inputFile.errorString());
        openWarning.exec();
        return false;
    }

    // Validation
    QString schema = qApp->applicationDirPath() + "/data/EBU_CORE_20110915.xsd";
    Validator validator;
    if (!validator.validate(filename, schema)) {
        Validator::ValidatorError error = validator.error();
        switch (error) {
        case Validator::ValidatorNotFound:
            QMessageBox::warning(this, tr("Validator"),
                                 tr("xmllint was not found in the application's PATH,"
                                    "thus no validation has been performed.\n"
                                    "The parsing can bring to unpredictable results."));
            break;
        case Validator::DocumentNotValid:
        {
            QMessageBox validatorWarning(this);
            validatorWarning.setIcon(QMessageBox::Warning);
            validatorWarning.setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Minimum);
            validatorWarning.setWindowTitle(tr("Validator"));
            validatorWarning.setText(tr("Invalid input file.\n"
                                        "Should you choose to ignore this error, "
                                        "the parsing can bring to unpredictable results."));
            validatorWarning.setDetailedText(validator.validationErrorMessage());
            validatorWarning.setStandardButtons(QMessageBox::Abort | QMessageBox::Ignore);
            validatorWarning.setDefaultButton(QMessageBox::Abort);
            int i = validatorWarning.exec();
            if (i != QMessageBox::Ignore)
                return false;
            break;
        }
        case Validator::DocumentValid:
            break;
        case Validator::Unknown:
        default:
        {
            QMessageBox validatorWarning(this);
            validatorWarning.setIcon(QMessageBox::Warning);
            validatorWarning.setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Minimum);
            validatorWarning.setWindowTitle(tr("Validator"));
            validatorWarning.setText(tr("Unexpected error from validator"));
            validatorWarning.setDetailedText(validator.returnMessage());
            validatorWarning.setStandardButtons(QMessageBox::Ignore |
                                                QMessageBox::Abort);
            validatorWarning.setDefaultButton(QMessageBox::Abort);
            int ret = validatorWarning.exec();
            if (ret == QMessageBox::Abort)
                return false;
        }
        }
    }

    // Parsing
    EbuParser parser;
    if (!parser.parseFromFile(inputFile)) {
        QMessageBox parserWarning(this);
        parserWarning.setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Minimum);
        parserWarning.setIcon(QMessageBox::Warning);
        parserWarning.setWindowTitle(tr("QEbu Parser"));
        parserWarning.setText(tr("Invalid input file."));
        parserWarning.setDetailedText(parser.errorMsg());
        parserWarning.setStandardButtons(QMessageBox::Ok);
        parserWarning.setDefaultButton(QMessageBox::Ok);
        parserWarning.exec();
        return false;
    }

    // All has gone well (we hope).
    QMessageBox::information(this, tr("QEbu Parser"),
                             tr("Metadata imported successfully."));
    if (m_ebuCoreMain)
        delete m_ebuCoreMain;
    m_ebuCoreMain = parser.root();
    resetView();
    // QFileInfo is used to remove the pathname and extract only the true filename.
    QFileInfo fi(filename);
    m_currentDocument->setText(tr("%1 opened at %2").arg(fi.fileName()).arg(QTime::currentTime().toString()));
    return true;
}
Exemplo n.º 28
0
TEST(ValidatorTest, ArrayTwoBytesTooShortBytesize2) {
  std::string const value("\x03\x05\x00", 3);

  Validator validator;
  ASSERT_VELOCYPACK_EXCEPTION(validator.validate(value.c_str(), value.size()), Exception::ValidatorInvalidLength);
}
Exemplo n.º 29
0
TEST(ValidatorTest, ArrayTwoBytes) {
  std::string const value("\x03\x04\x00\x18", 4);

  Validator validator;
  ASSERT_TRUE(validator.validate(value.c_str(), value.size()));
}
Exemplo n.º 30
0
TEST(ValidatorTest, CustomOneByteFAZeroLength) {
  std::string const value("\xfa\x00\x00\x00\x00", 5);

  Validator validator;
  ASSERT_VELOCYPACK_EXCEPTION(validator.validate(value.c_str(), value.size()), Exception::ValidatorInvalidLength);
}