diff options
author | Jörg Frings-Fürst <debian@jff.email> | 2018-09-30 14:11:00 +0200 |
---|---|---|
committer | Jörg Frings-Fürst <debian@jff.email> | 2018-09-30 14:11:00 +0200 |
commit | 0ac947a9070322180e94d1b71e30836cce4d74bc (patch) | |
tree | 4a6f3923c250377536a5004ed203768111a1d27f /test | |
parent | eca5837e235a356c8db9416bbbc13577db3e6f76 (diff) | |
parent | 01b2b5ec9177046f64c6d0a6e73a6ac8a42089a1 (diff) |
Merge branch 'feature/upstream' into develop
Diffstat (limited to 'test')
-rw-r--r-- | test/NaturalCollate-Test.vala | 136 | ||||
l--------- | test/NaturalCollate.vala | 1 | ||||
-rw-r--r-- | test/meson.build | 5 | ||||
-rwxr-xr-x | test/server.py | 102 |
4 files changed, 244 insertions, 0 deletions
diff --git a/test/NaturalCollate-Test.vala b/test/NaturalCollate-Test.vala new file mode 100644 index 0000000..64c7ce5 --- /dev/null +++ b/test/NaturalCollate-Test.vala @@ -0,0 +1,136 @@ +void add_trailing_numbers_tests () { + Test.add_func ("/functional/collation/trailing_numbers", () => { + string a = "100foo"; + string b = "100bar"; + string coll_a = NaturalCollate.collate_key(a); + string coll_b = NaturalCollate.collate_key(b); + assert(strcmp(coll_a, coll_b) > 0); + assert(strcmp(a,b) > 0); + assert(NaturalCollate.compare(a,b) == strcmp(coll_a, coll_b)); + + string atrail = "00100foo"; + string btrail = "0100bar"; + + string coll_atrail = NaturalCollate.collate_key(a); + string coll_btrail = NaturalCollate.collate_key(b); + assert(strcmp(coll_a, coll_atrail) == 0); + assert(strcmp(coll_b, coll_btrail) == 0); + + assert(strcmp(coll_atrail, coll_btrail) > 0); + assert(strcmp(atrail,btrail) < 0); + assert(NaturalCollate.compare(atrail,btrail) == strcmp(coll_atrail, coll_btrail)); + + }); +} + +void add_numbers_tail_tests () { + Test.add_func ("/functional/collation/numbers_tail", () => { + string a = "aaa00100"; + string b = "aaa02"; + string coll_a = NaturalCollate.collate_key(a); + string coll_b = NaturalCollate.collate_key(b); + assert(strcmp(coll_a, coll_b) > 0); + assert(strcmp(a,b) < 0); + assert(NaturalCollate.compare(a,b) == strcmp(coll_a, coll_b)); + }); +} + +void add_dots_tests () { + Test.add_func ("/functional/collation/dots", () => { + string sa = "Foo01.jpg"; + string sb = "Foo2.jpg"; + string sc = "Foo3.jpg"; + string sd = "Foo10.jpg"; + + assert (strcmp(sa, sd) < 0); + assert (strcmp(sd, sb) < 0); + assert (strcmp(sb, sc) < 0); + + string coll_sa = NaturalCollate.collate_key(sa); + string coll_sb = NaturalCollate.collate_key(sb); + string coll_sc = NaturalCollate.collate_key(sc); + string coll_sd = NaturalCollate.collate_key(sd); + + assert (strcmp(coll_sa, coll_sb) < 0); + assert (strcmp(coll_sb, coll_sc) < 0); + assert (strcmp(coll_sc, coll_sd) < 0); + }); +} + +void add_bigger_as_strcmp_tests () { + Test.add_func ("/functional/collation/bigger_as_strcmp", () => { + string a = "foo"; + string b = "bar"; + string coll_a = NaturalCollate.collate_key(a); + string coll_b = NaturalCollate.collate_key(b); + assert(strcmp(coll_a,coll_b) > 0); + assert(strcmp(a,b) > 0); + assert(NaturalCollate.compare(a,b) == strcmp(coll_a, coll_b)); + + a = "foo0001"; + b = "bar0000"; + coll_a = NaturalCollate.collate_key(a); + coll_b = NaturalCollate.collate_key(b); + assert(strcmp(coll_a,coll_b) > 0); + assert(strcmp(a,b) > 0); + assert(NaturalCollate.compare(a,b) == strcmp(coll_a, coll_b)); + + a = "bar010"; + b = "bar01"; + coll_a = NaturalCollate.collate_key(a); + coll_b = NaturalCollate.collate_key(b); + assert(strcmp(coll_a,coll_b) > 0); + assert(strcmp(a,b) > 0); + assert(NaturalCollate.compare(a,b) == strcmp(coll_a, coll_b)); + }); +} + +void add_numbers_tests() { + Test.add_func ("/functional/collation/numbers", () => { + string a = "0"; + string b = "1"; + string coll_a = NaturalCollate.collate_key(a); + string coll_b = NaturalCollate.collate_key(b); + assert(strcmp(coll_a, coll_b) < 0); + + a = "100"; + b = "101"; + coll_a = NaturalCollate.collate_key(a); + coll_b = NaturalCollate.collate_key(b); + assert(strcmp(coll_a, coll_b) < 0); + + a = "2"; + b = "10"; + coll_a = NaturalCollate.collate_key(a); + coll_b = NaturalCollate.collate_key(b); + assert(strcmp(coll_a, coll_b) < 0); + + a = "b20"; + b = "b100"; + coll_a = NaturalCollate.collate_key(a); + coll_b = NaturalCollate.collate_key(b); + assert(strcmp(coll_a, coll_b) < 0); + }); +} + +void add_ignore_leading_zeros_tests () { + Test.add_func ("/functional/collation/ignore_leading_zeros", () => { + string a = "bar0000010"; + string b = "bar10"; + string coll_a = NaturalCollate.collate_key(a); + string coll_b = NaturalCollate.collate_key(b); + assert(strcmp(coll_a,coll_b) == 0); + }); +} + +void main (string[] args) { + GLib.Intl.setlocale(GLib.LocaleCategory.ALL, ""); + Test.init (ref args); + add_trailing_numbers_tests(); + add_numbers_tail_tests(); + add_bigger_as_strcmp_tests(); + add_ignore_leading_zeros_tests(); + add_numbers_tests(); + add_dots_tests(); + Test.run(); +} diff --git a/test/NaturalCollate.vala b/test/NaturalCollate.vala new file mode 120000 index 0000000..a2ae18d --- /dev/null +++ b/test/NaturalCollate.vala @@ -0,0 +1 @@ +../src/NaturalCollate.vala
\ No newline at end of file diff --git a/test/meson.build b/test/meson.build new file mode 100644 index 0000000..de1f012 --- /dev/null +++ b/test/meson.build @@ -0,0 +1,5 @@ +natural_collate_test = executable('natural-collate-test', + ['NaturalCollate-Test.vala', 'NaturalCollate.vala'], + dependencies : gio) + +test('natural-collate', natural_collate_test) diff --git a/test/server.py b/test/server.py new file mode 100755 index 0000000..10f3c70 --- /dev/null +++ b/test/server.py @@ -0,0 +1,102 @@ +#!/usr/bin/env python3 +# +# Copyright 2017 Jens Georg <mail@jensge.org> +# +# Permission is hereby granted, free of charge, to any person obtaining a copy of +# this software and associated documentation files (the "Software"), to deal in +# the Software without restriction, including without limitation the rights to +# use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies +# of the Software, and to permit persons to whom the Software is furnished to do +# so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. +# + +import http.server +import cgi +import urllib.parse +import time + +# This is a simple implementation of the Piwigo protocol to run locally +# for testing publishing in offline-situations + +class SimpleRequestHandler(http.server.BaseHTTPRequestHandler): + def do_POST(self): + self.log_message("Got POST request for path " + self.path) + ctype, pdict = cgi.parse_header(self.headers['content-type']) + self.log_message("Content-Type = " + ctype) + if ctype == 'multipart/form-data': + pdict['boundary'] = bytes(pdict['boundary'], 'utf-8') + postvars = cgi.parse_multipart(self.rfile, pdict) + elif ctype == 'application/x-www-form-urlencoded': + length = int(self.headers['content-length']) + postvars = urllib.parse.parse_qs(self.rfile.read(length), + keep_blank_values=1) + else: + postvars = {} + + try: + method = postvars[b'method'][0] + except: + method = postvars['method'][0] + + self.log_message("Received method call for " + str(method)) + time.sleep(1) + + if self.path == '/ws.php': + try: + + if method == b'pwg.session.login': + self.send_response(200) + self.send_header('Content-type', 'text/xml') + self.send_header('Set-Cookie', 'pwg_id="12345"') + self.end_headers() + self.wfile.write(b'<?xml version="1.0"?><piwigo stat="ok"></piwigo>') + return + elif method == b'pwg.session.getStatus': + self.send_response(200) + self.send_header('Content-type', 'text/xml') + self.send_header('Set-Cookie', 'pwg_id="12345"') + self.end_headers() + self.wfile.write(b'<?xml version="1.0"?><piwigo stat="ok"><username>test</username></piwigo>') + return + elif method == b'pwg.categories.getList': + self.send_response(200) + self.send_header('Content-type', 'text/xml') + self.send_header('Set-Cookie', 'pwg_id="12345"') + self.end_headers() + self.wfile.write(b'<?xml version="1.0"?><piwigo stat="ok"><categories></categories></piwigo>') + return + elif method == b'pwg.categories.add': + self.send_response(200) + self.send_header('Set-Cookie', 'pwg_id="12345"') + self.end_headers() + self.wfile.write(b'<?xml version="1.0"?><piwigo stat="ok"><id>765</id></piwigo>') + return + elif method == b'pwg.images.addSimple': + self.send_response(200) + self.send_header('Set-Cookie', 'pwg_id="12345"') + self.end_headers() + self.wfile.write(b'<?xml version="1.0"?><piwigo stat="ok"></piwigo>') + return + except: + self.log_error('Unknown method {0}'.format(postvars[b'method'])) + pass + + self.send_response(500) + +def run(server_class = http.server.HTTPServer, handler_class = SimpleRequestHandler): + server_address = ('127.0.0.1', 8080) + httpd = server_class(server_address, handler_class) + httpd.serve_forever() + +run() |