blob: aca69e6bcebae4140de1f0b04d901a1015235416 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
|
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
/**
* \class document::TestDocMan
* \ingroup base
*
* \brief Utility for unit tests that need document manager and documents.
*
* This test class sets up a document manager, and defines a few document types
* for use in testing.
*
* The following document types are defined by this manager
* (add more when needed):
*
* testtype1
* headerval int (header variable)
* content string (body variable)
*/
#pragma once
#include "testdocrepo.h"
#include <vespa/document/fieldvalue/document.h>
#include <vespa/document/datatype/documenttype.h>
namespace document {
class Document;
class TestDocMan {
static std::vector<char> _buffer;
TestDocRepo _test_repo;
std::shared_ptr<const DocumentTypeRepo> _repo;
const DocumenttypesConfig *_typeCfg;
public:
TestDocMan();
~TestDocMan();
void setTypeRepo(const std::shared_ptr<const DocumentTypeRepo> &repo);
const DocumentTypeRepo& getTypeRepo() const { return *_repo; }
std::shared_ptr<const DocumentTypeRepo> getTypeRepoSP() const { return _repo; }
const DocumenttypesConfig *getTypeConfig() const { return _typeCfg; }
/** Create test document. */
std::unique_ptr<Document> createDocument(
const std::string& content = "This is the contents of "
"the test document.\nIt ain't much.\n",
const std::string& uri = "id:test:testdoctype1::test",
const std::string& type = "testdoctype1") const;
/** Create random document from given seed. */
std::unique_ptr<Document> createRandomDocument(
int seed = 0, int maxContentSize = 0x80) const;
/** Create random document from given seed belonging to given location */
std::unique_ptr<Document> createRandomDocumentAtLocation(
int location, int seed = 0, int maxContentSize = 0x80) const;
std::unique_ptr<Document> createRandomDocumentAtLocation(
int location, int seed, int minContentSize, int maxContentSize) const;
/** Create random document of given type from given seed. */
std::unique_ptr<Document> createRandomDocument(
const std::string& type, int seed = 0,
int maxContentSize = 0x80) const;
static std::string generateRandomContent(uint32_t size);
};
} // document
|