// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. #include #include #include #include #include #include #include #include #include #include #include #include using vespalib::StringTokenizer; namespace document { namespace { Document::UP createTestDocument(const DocumentTypeRepo& repo) { const DocumentType* type(repo.getDocumentType("testdoc")); auto doc = std::make_unique(repo, *type, DocumentId("id:ns:testdoc::crawler/http://www.ntnu.no/")); std::string s("humlepungens buffer"); ByteBuffer bb(s.c_str(), s.size()); doc->setValue(doc->getField("intattr"), IntFieldValue(50)); doc->setValue(doc->getField("rawattr"), RawFieldValue("readable hei der", 7)); doc->setValue(doc->getField("floatattr"), FloatFieldValue(3.56)); doc->setValue(doc->getField("stringattr"), StringFieldValue("tjo hei")); doc->setValue(doc->getField("doubleattr"), DoubleFieldValue(17.78623142376453)); doc->setValue(doc->getField("longattr"), LongFieldValue(346234765345239657LL)); doc->setValue(doc->getField("byteattr"), ByteFieldValue('J')); ArrayFieldValue val(doc->getField("rawarrayattr").getDataType()); RawFieldValue rawVal("readable hei", 3); val.add(rawVal); RawFieldValue rawVal2("readable hallo", 5); val.add(rawVal2); RawFieldValue rawVal3("readable hei der", 7); val.add(rawVal3); doc->setValue(doc->getField("rawarrayattr"), val); auto doc2 = std::make_unique(repo, *type, DocumentId("id:ns:testdoc::crawler/http://www.ntnu.no/2")); doc2->setValue(doc2->getField("stringattr"), StringFieldValue("tjo hei paa du")); doc->setValue(doc->getField("docfield"), *doc2); return doc; } DocumentUpdate::UP createTestDocumentUpdate(const DocumentTypeRepo& repo) { const DocumentType* type(repo.getDocumentType("testdoc")); DocumentId id("id:ns:testdoc::crawler/http://www.ntnu.no/"); auto up = std::make_unique(repo, *type, id); up->addUpdate(FieldUpdate(type->getField("intattr")) .addUpdate(std::make_unique(std::make_unique(7)))); up->addUpdate(FieldUpdate(type->getField("stringattr")) .addUpdate(std::make_unique(StringFieldValue::make("New value")))); up->addUpdate(FieldUpdate(type->getField("arrayattr")) .addUpdate(std::make_unique(std::make_unique(123))) .addUpdate(std::make_unique(std::make_unique(456)))); up->addUpdate(FieldUpdate(type->getField("arrayattr")) .addUpdate(std::make_unique(std::make_unique(123))) .addUpdate(std::make_unique(std::make_unique(456))) .addUpdate(std::make_unique(std::make_unique(789)))); return up; } } // anonymous ns TEST(TestXml, testSimpleUsage) { DocumentTypeRepo repo(readDocumenttypesConfig(TEST_PATH("data/defaultdoctypes.cfg"))); Document::UP doc1(createTestDocument(repo)); doc1->setValue(doc1->getField("stringattr"), StringFieldValue("tjohei���")); std::string expected = "\n" " 17.7862\n" " 50\n" " 3.56\n" " 346234765345239657\n" " 74\n" " \n" " cmVh\n" " cmVhZGE=\n" " cmVhZGFibA==\n" " \n" " cmVhZGFibA==\n" " tjohei���\n" " \n" " \n" " tjo hei paa du\n" " \n" " \n" " humlepungens buffer\n" ""; } TEST(TestXml, testDocumentUpdate) { DocumentTypeRepo repo(readDocumenttypesConfig(TEST_PATH("data/defaultdoctypes.cfg"))); DocumentUpdate::UP up1(createTestDocumentUpdate(repo)); std::string expected = "\n" " \n" " 7\n" " \n" " \n" " New value\n" " \n" " \n" " 123\n" " 456\n" " \n" " \n" " 123\n" " 456\n" " 789\n" " \n" ""; EXPECT_EQ(expected, up1->toXml(" ")); } } // document