Skip to content

Commit

Permalink
Pass the litmus prop tests
Browse files Browse the repository at this point in the history
  • Loading branch information
gedaiu committed Mar 8, 2015
1 parent 0f946fa commit f3100ab
Show file tree
Hide file tree
Showing 7 changed files with 197 additions and 41 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,7 @@ __dummy.html
dub.selections.json

__test__library__

vibe-dav

vibe-dav.sublime-project
15 changes: 13 additions & 2 deletions dub.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,19 @@
"authors": ["Szabo Bogdan"],
"license": "MIT",
"dependencies": {
"vibe-d": "~>0.7.22"
"vibe-d": "~>0.7.22",
"tested": ">=0.9.0"
},

"targetType": "library"
"targetType": "library",

"configurations": [
{
"name": "tested",
"mainSourceFile": "source/test.d",
"versions": ["VibeCustomMain"],
"dflags": ["-unittest"],
"targetType": "executable"
}
]
}
36 changes: 36 additions & 0 deletions results.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
[
{"name": "basic check for getHeaderValue", "qualifiedName": "vibedav.base.__unittestL50_1", "instrumentation": [{"name": "gcPoolSize", "value": 0, "timestamp": 7e-06}, {"name": "gcUsedSize", "value": 0, "timestamp": 7e-06}, {"name": "gcFreeListSize", "value": 0, "timestamp": 7e-06}], "success": true, "duration": 7e-06},
{"name": "getHeaderValue with default value", "qualifiedName": "vibedav.base.__unittestL58_2", "instrumentation": [{"name": "gcPoolSize", "value": 0, "timestamp": 2e-06}, {"name": "gcUsedSize", "value": 0, "timestamp": 2e-06}, {"name": "gcFreeListSize", "value": 0, "timestamp": 2e-06}], "success": true, "duration": 2e-06},
{"name": "check if getHeaderValue fails", "qualifiedName": "vibedav.base.__unittestL65_3", "instrumentation": [{"name": "gcPoolSize", "value": 0, "timestamp": 2.1e-05}, {"name": "gcUsedSize", "value": 2208, "timestamp": 2.1e-05}, {"name": "gcFreeListSize", "value": 1888, "timestamp": 2.1e-05}], "success": true, "duration": 2.1e-05},
{"name": "exists", "qualifiedName": "vibedav.file.DavFileResource.__unittestL168_4", "instrumentation": [{"name": "gcPoolSize", "value": 0, "timestamp": 0.002108}, {"name": "gcUsedSize", "value": 79040, "timestamp": 0.002108}, {"name": "gcFreeListSize", "value": 1.84467e+19, "timestamp": 0.002108}], "success": true, "duration": 0.002108},
{"name": "copy file", "qualifiedName": "vibedav.file.DavFileResource.__unittestL242_5", "instrumentation": [{"name": "gcPoolSize", "value": 0, "timestamp": 0.000517}, {"name": "gcUsedSize", "value": 21936, "timestamp": 0.000517}, {"name": "gcFreeListSize", "value": 1.84467e+19, "timestamp": 0.000517}], "success": true, "duration": 0.000517},
{"name": "copy dir", "qualifiedName": "vibedav.file.DavFileResource.__unittestL259_6", "instrumentation": [{"name": "gcPoolSize", "value": 0, "timestamp": 0.001104}, {"name": "gcUsedSize", "value": 63248, "timestamp": 0.001104}, {"name": "gcFreeListSize", "value": 1.84467e+19, "timestamp": 0.001104}], "success": true, "duration": 0.001104},
{"name": "string prop", "qualifiedName": "vibedav.prop.__unittestL333_7", "instrumentation": [{"name": "gcPoolSize", "value": 0, "timestamp": 1.1e-05}, {"name": "gcUsedSize", "value": 176, "timestamp": 1.1e-05}, {"name": "gcFreeListSize", "value": 1.84467e+19, "timestamp": 1.1e-05}], "success": true, "duration": 1.1e-05},
{"name": "tag prop", "qualifiedName": "vibedav.prop.__unittestL339_8", "instrumentation": [{"name": "gcPoolSize", "value": 0, "timestamp": 2.6e-05}, {"name": "gcUsedSize", "value": 2592, "timestamp": 2.6e-05}, {"name": "gcFreeListSize", "value": 1504, "timestamp": 2.6e-05}], "success": true, "duration": 2.6e-05},
{"name": "check if tags can be accessed from other references", "qualifiedName": "vibedav.prop.__unittestL346_9", "instrumentation": [{"name": "gcPoolSize", "value": 0, "timestamp": 2.6e-05}, {"name": "gcUsedSize", "value": 4832, "timestamp": 2.6e-05}, {"name": "gcFreeListSize", "value": 1.84467e+19, "timestamp": 2.6e-05}], "success": true, "duration": 2.6e-05},
{"name": "remove child tags", "qualifiedName": "vibedav.prop.__unittestL358_10", "instrumentation": [{"name": "gcPoolSize", "value": 0, "timestamp": 2.3e-05}, {"name": "gcUsedSize", "value": 7232, "timestamp": 2.3e-05}, {"name": "gcFreeListSize", "value": 960, "timestamp": 2.3e-05}], "success": true, "duration": 2.3e-05},
{"name": "filter tags by tag name", "qualifiedName": "vibedav.prop.__unittestL371_11", "instrumentation": [{"name": "gcPoolSize", "value": 0, "timestamp": 1.2e-05}, {"name": "gcUsedSize", "value": 656, "timestamp": 1.2e-05}, {"name": "gcFreeListSize", "value": 1.84467e+19, "timestamp": 1.2e-05}], "success": true, "duration": 1.2e-05},
{"name": "set tag value property", "qualifiedName": "vibedav.prop.__unittestL389_12", "instrumentation": [{"name": "gcPoolSize", "value": 0, "timestamp": 2.3e-05}, {"name": "gcUsedSize", "value": 2592, "timestamp": 2.3e-05}, {"name": "gcFreeListSize", "value": 1504, "timestamp": 2.3e-05}], "success": true, "duration": 2.3e-05},
{"name": "set namespace attr", "qualifiedName": "vibedav.prop.__unittestL398_13", "instrumentation": [{"name": "gcPoolSize", "value": 0, "timestamp": 1.7e-05}, {"name": "gcUsedSize", "value": 2592, "timestamp": 1.7e-05}, {"name": "gcFreeListSize", "value": 1504, "timestamp": 1.7e-05}], "success": true, "duration": 1.7e-05},
{"name": "set a tag namesapace prefix", "qualifiedName": "vibedav.prop.__unittestL407_14", "instrumentation": [{"name": "gcPoolSize", "value": 0, "timestamp": 2.3e-05}, {"name": "gcUsedSize", "value": 2736, "timestamp": 2.3e-05}, {"name": "gcFreeListSize", "value": 1360, "timestamp": 2.3e-05}], "success": true, "duration": 2.3e-05},
{"name": "get tag prefix", "qualifiedName": "vibedav.prop.__unittestL416_15", "instrumentation": [{"name": "gcPoolSize", "value": 0, "timestamp": 2.3e-05}, {"name": "gcUsedSize", "value": 4960, "timestamp": 2.3e-05}, {"name": "gcFreeListSize", "value": 1.84467e+19, "timestamp": 2.3e-05}], "success": true, "duration": 2.3e-05},
{"name": "add a tag with an unknown ns prefix", "qualifiedName": "vibedav.prop.__unittestL426_16", "instrumentation": [{"name": "gcPoolSize", "value": 0, "timestamp": 6e-05}, {"name": "gcUsedSize", "value": 9232, "timestamp": 6e-05}, {"name": "gcFreeListSize", "value": 1.84467e+19, "timestamp": 6e-05}], "success": true, "duration": 6e-05},
{"name": "add same name tag with different ns", "qualifiedName": "vibedav.prop.__unittestL443_17", "instrumentation": [{"name": "gcPoolSize", "value": 0, "timestamp": 2e-05}, {"name": "gcUsedSize", "value": 2640, "timestamp": 2e-05}, {"name": "gcFreeListSize", "value": 1456, "timestamp": 2e-05}], "success": true, "duration": 2e-05},
{"name": "get a namespace name from a prefixed tag", "qualifiedName": "vibedav.prop.__unittestL464_18", "instrumentation": [{"name": "gcPoolSize", "value": 0, "timestamp": 2.8e-05}, {"name": "gcUsedSize", "value": 4960, "timestamp": 2.8e-05}, {"name": "gcFreeListSize", "value": 1.84467e+19, "timestamp": 2.8e-05}], "success": true, "duration": 2.8e-05},
{"name": "parse a string without any tags", "qualifiedName": "vibedav.prop.__unittestL728_19", "instrumentation": [{"name": "gcPoolSize", "value": 0, "timestamp": 2.3e-05}, {"name": "gcUsedSize", "value": 432, "timestamp": 2.3e-05}, {"name": "gcFreeListSize", "value": 1.84467e+19, "timestamp": 2.3e-05}], "success": true, "duration": 2.3e-05},
{"name": "parse a string with a tag", "qualifiedName": "vibedav.prop.__unittestL734_20", "instrumentation": [{"name": "gcPoolSize", "value": 0, "timestamp": 3e-05}, {"name": "gcUsedSize", "value": 1120, "timestamp": 3e-05}, {"name": "gcFreeListSize", "value": 1.84467e+19, "timestamp": 3e-05}], "success": true, "duration": 3e-05},
{"name": "parse a string without imbricated tags", "qualifiedName": "vibedav.prop.__unittestL742_21", "instrumentation": [{"name": "gcPoolSize", "value": 0, "timestamp": 2.6e-05}, {"name": "gcUsedSize", "value": 2128, "timestamp": 2.6e-05}, {"name": "gcFreeListSize", "value": 1.84467e+19, "timestamp": 2.6e-05}], "success": true, "duration": 2.6e-05},
{"name": "parse a string with imbricated tags", "qualifiedName": "vibedav.prop.__unittestL750_22", "instrumentation": [{"name": "gcPoolSize", "value": 0, "timestamp": 5e-05}, {"name": "gcUsedSize", "value": 1824, "timestamp": 5e-05}, {"name": "gcFreeListSize", "value": 1.84467e+19, "timestamp": 5e-05}], "success": true, "duration": 5e-05},
{"name": "check invalid namespaces", "qualifiedName": "vibedav.prop.__unittestL759_23", "instrumentation": [{"name": "gcPoolSize", "value": 0, "timestamp": 3.4e-05}, {"name": "gcUsedSize", "value": 3248, "timestamp": 3.4e-05}, {"name": "gcFreeListSize", "value": 848, "timestamp": 3.4e-05}], "success": true, "duration": 3.4e-05},
{"name": "check valid namespaces", "qualifiedName": "vibedav.prop.__unittestL771_24", "instrumentation": [{"name": "gcPoolSize", "value": 0, "timestamp": 3.2e-05}, {"name": "gcUsedSize", "value": 2192, "timestamp": 3.2e-05}, {"name": "gcFreeListSize", "value": 1.84467e+19, "timestamp": 3.2e-05}], "success": true, "duration": 3.2e-05},
{"name": "parse xml attribute", "qualifiedName": "vibedav.prop.__unittestL778_25", "instrumentation": [{"name": "gcPoolSize", "value": 0, "timestamp": 2.4e-05}, {"name": "gcUsedSize", "value": 912, "timestamp": 2.4e-05}, {"name": "gcFreeListSize", "value": 1.84467e+19, "timestamp": 2.4e-05}], "success": true, "duration": 2.4e-05},
{"name": "normalize xml string", "qualifiedName": "vibedav.prop.__unittestL784_26", "instrumentation": [{"name": "gcPoolSize", "value": 0, "timestamp": 1.6e-05}, {"name": "gcUsedSize", "value": 64, "timestamp": 1.6e-05}, {"name": "gcFreeListSize", "value": 1.84467e+19, "timestamp": 1.6e-05}], "success": true, "duration": 1.6e-05},
{"name": "normalize `/` and `<` in attr values", "qualifiedName": "vibedav.prop.__unittestL790_27", "instrumentation": [{"name": "gcPoolSize", "value": 0, "timestamp": 1.4e-05}, {"name": "gcUsedSize", "value": 64, "timestamp": 1.4e-05}, {"name": "gcFreeListSize", "value": 1.84467e+19, "timestamp": 1.4e-05}], "success": true, "duration": 1.4e-05},
{"name": "access nodes without passing the ns", "qualifiedName": "vibedav.prop.__unittestL796_28", "instrumentation": [{"name": "gcPoolSize", "value": 0, "timestamp": 4.5e-05}, {"name": "gcUsedSize", "value": 1872, "timestamp": 4.5e-05}, {"name": "gcFreeListSize", "value": 1.84467e+19, "timestamp": 4.5e-05}], "success": true, "duration": 4.5e-05},
{"name": "parse self closing tags", "qualifiedName": "vibedav.prop.__unittestL803_29", "instrumentation": [{"name": "gcPoolSize", "value": 0, "timestamp": 3.8e-05}, {"name": "gcUsedSize", "value": 576, "timestamp": 3.8e-05}, {"name": "gcFreeListSize", "value": 1.84467e+19, "timestamp": 3.8e-05}], "success": true, "duration": 3.8e-05},
{"name": "check ?xml tag parsing", "qualifiedName": "vibedav.prop.__unittestL809_30", "instrumentation": [{"name": "gcPoolSize", "value": 0, "timestamp": 5.1e-05}, {"name": "gcUsedSize", "value": 3248, "timestamp": 5.1e-05}, {"name": "gcFreeListSize", "value": 1.84467e+19, "timestamp": 5.1e-05}], "success": true, "duration": 5.1e-05},
{"name": "check if the parsing fails to check the parents", "qualifiedName": "vibedav.prop.__unittestL815_31", "instrumentation": [{"name": "gcPoolSize", "value": 0, "timestamp": 4.3e-05}, {"name": "gcUsedSize", "value": 2384, "timestamp": 4.3e-05}, {"name": "gcFreeListSize", "value": 1.84467e+19, "timestamp": 4.3e-05}], "success": true, "duration": 4.3e-05},
{"name": "check child names with similar name", "qualifiedName": "vibedav.prop.__unittestL821_32", "instrumentation": [{"name": "gcPoolSize", "value": 0, "timestamp": 4.8e-05}, {"name": "gcUsedSize", "value": 1344, "timestamp": 4.8e-05}, {"name": "gcFreeListSize", "value": 1.84467e+19, "timestamp": 4.8e-05}], "success": true, "duration": 4.8e-05},
{"name": "allow to have childrens with the same tag name", "qualifiedName": "vibedav.prop.__unittestL827_33", "instrumentation": [{"name": "gcPoolSize", "value": 0, "timestamp": 4.2e-05}, {"name": "gcUsedSize", "value": 2656, "timestamp": 4.2e-05}, {"name": "gcFreeListSize", "value": 1.84467e+19, "timestamp": 4.2e-05}], "success": true, "duration": 4.2e-05},
{"name": "value given for tag with null ns", "qualifiedName": "vibedav.prop.__unittestL833_34", "instrumentation": [{"name": "gcPoolSize", "value": 0, "timestamp": 6.1e-05}, {"name": "gcUsedSize", "value": 2544, "timestamp": 6.1e-05}, {"name": "gcFreeListSize", "value": 1.84467e+19, "timestamp": 6.1e-05}], "success": true, "duration": 6.1e-05}
]
37 changes: 37 additions & 0 deletions source/test.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import std.typetuple;

import vibedav.base;
import vibedav.file;
import vibedav.prop;
import vibedav.util;
alias allModules = TypeTuple!(vibedav.base, vibedav.file, vibedav.prop, vibedav.util);

import std.stdio;
import core.runtime;

shared bool result;

int main() {

if(!result) {
return 1;
}

writeln("All unit tests have been run successfully.");

return 0;
}
shared static this() {
version (Have_tested) {
import tested;
import core.runtime;
import std.exception;
Runtime.moduleUnitTester = () => true;

//runUnitTests!app(new JsonTestResultWriter("results.json"));

//enforce(runUnitTests!allModules(new ConsoleTestResultWriter), "Unit tests failed.");
result = runUnitTests!allModules(new JsonTestResultWriter("results.json"));
}
}

56 changes: 33 additions & 23 deletions source/vibedav/base.d
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import std.stdio : writeln; //todo: remove this
import std.typecons;
import std.uri;
import std.uuid;
import tested;

alias HeaderList = DictionaryList!(string, false, 32L);

Expand All @@ -45,19 +46,22 @@ string getHeaderValue(HeaderList headers, string name, string defaultValue = "")
return value;
}

@name("basic check for getHeaderValue")
unittest {
HeaderList list;
list["key"] = "value";
auto val = getHeaderValue(list, "key");
assert(val == "value");
}

@name("getHeaderValue with default value")
unittest {
HeaderList list;
auto val = getHeaderValue(list, "key", "default");
assert(val == "default");
}

@name("check if getHeaderValue fails")
unittest {
bool raised = false;

Expand Down Expand Up @@ -327,38 +331,44 @@ class DavResource {

auto document = parseXMLProp(content);

//set properties
auto setList = [document].getTagChilds("propertyupdate")
.getTagChilds("set")
.getTagChilds("prop");

foreach(prop; setList) {
foreach(string key, p; prop) {
properties[key] = p;
result ~= `<d:propstat><d:prop>` ~ p.toString ~ `</d:prop>`;
HTTPStatus status = HTTPStatus.ok;
result ~= `<d:status>HTTP/1.1 ` ~ status.to!int.to!string ~ ` ` ~ status.to!string ~ `</d:status></d:propstat>`;
}
}

//remove properties
auto removeList = [document].getTagChilds("propertyupdate")
.getTagChilds("remove")
.getTagChilds("prop");

foreach(prop; removeList)
foreach(string key, p; prop) {
properties.remove(key);
result ~= `<d:propstat><d:prop>` ~ p.toString ~ `</d:prop>`;
HTTPStatus status = HTTPStatus.notFound;
result ~= `<d:status>HTTP/1.1 ` ~ status.to!int.to!string ~ ` ` ~ status.to!string ~ `</d:status></d:propstat>`;
auto updateList = [document].getTagChilds("propertyupdate");

foreach(string key, item; updateList[0]) {
if(item.tagName == "remove") {
auto removeList = [item].getTagChilds("prop");

foreach(prop; removeList)
foreach(string key, p; prop) {
properties.remove(key);
result ~= `<d:propstat><d:prop>` ~ p.toString ~ `</d:prop>`;
HTTPStatus status = HTTPStatus.notFound;
result ~= `<d:status>HTTP/1.1 ` ~ status.to!int.to!string ~ ` ` ~ status.to!string ~ `</d:status></d:propstat>`;
}
}
else if(item.tagName == "set") {
auto setList = [item].getTagChilds("prop");

foreach(prop; setList) {
foreach(string key, p; prop) {
writeln("set", key);
properties[key] = p;
result ~= `<d:propstat><d:prop>` ~ p.toString ~ `</d:prop>`;
HTTPStatus status = HTTPStatus.ok;
result ~= `<d:status>HTTP/1.1 ` ~ status.to!int.to!string ~ ` ` ~ status.to!string ~ `</d:status></d:propstat>`;
}
}
}
}

if(description != "")
result ~= `<d:responsedescription>` ~ description ~ `</d:responsedescription>`;

result ~= `</d:response></d:multistatus>`;

writeln("properties:", properties);

string strUrl = url.toString;
dav.resourcePropStorage[strUrl] = properties;

Expand Down
5 changes: 5 additions & 0 deletions source/vibedav/file.d
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ import std.typecons;
import std.uri;
import std.uuid;

import tested: testName = name;

/// File dav impplementation
class FileDav : Dav {
@property
Expand Down Expand Up @@ -162,6 +164,7 @@ final class DavFileResource : DavResource {
filePath.toString.remove;
}

@testName("exists")
unittest {
"level1/level2".mkdirRecurse;
"level1/level2/testFile1.txt".write("hello!");
Expand Down Expand Up @@ -235,6 +238,7 @@ final class DavFileResource : DavResource {
return retCode;
}

@testName("copy file")
unittest {
"testFile.txt".write("hello!");

Expand All @@ -251,6 +255,7 @@ final class DavFileResource : DavResource {
"testCopy.txt".remove;
}

@testName("copy dir")
unittest {
"level1/level2".mkdirRecurse;
"level1/level2/testFile.txt".write("hello!");
Expand Down
Loading

0 comments on commit f3100ab

Please sign in to comment.