Permalink
Browse files

Tidy up common_test suites; test larger driver I/O

  • Loading branch information...
hyperthunk committed Mar 17, 2011
1 parent e3ee467 commit 4f8325f78da627a48ab94b6b88a5b209023c9031
View
@@ -25,4 +25,5 @@ c_src/cscope.outcscope.out
*.swp
**/*.swp
inttest/deps/cspec
-inttest/bin/all_specs
+inttest/bin/all_specserlxsl.komodoproject
+.komodotools/
View
@@ -1,4 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!-- Komodo Project File - DO NOT EDIT -->
-<project id="0d2033f3-d0f3-4027-8cb4-5a97bde4ddcf" kpf_version="5" name="erlxsl.komodoproject">
-</project>
View
@@ -2,6 +2,8 @@
%% @copyright 2007 author.
%% common tests macros and functions
+-define(fixture(Config, File),
+ filename:join(?config(fixtures, Config), File)).
-define(TESTDOC(Doc), [{userdata,[{doc,Doc}]}]).
-define(NOT_IMPLEMENTED, {skip,"Not implemented."}).
-define(EXPORT_TESTS(Mod),
File renamed without changes.
View
@@ -42,12 +42,18 @@
-include("../include/test.hrl").
-include("../include/erlxsl.hrl").
-%% public api exports
-
%% automatically registers all exported functions as test cases
all() ->
?EXPORT_TESTS(?MODULE).
+init_per_testcase(_, Config) ->
+ DataDir = ?config(data_dir, Config),
+ Fixtures = test_support:get_fixture_dir(DataDir),
+ [{fixtures, Fixtures}|Config].
+
+end_per_testcase(_, _) ->
+ ok.
+
small_binaries_generate_placeholder_entries(_) ->
Xml = <<"<fragment><empty /></fragment>">>,
Xsl = <<"<?xml version='1.0'?>">>,
@@ -62,8 +68,9 @@ small_binaries_generate_placeholder_entries(_) ->
?assertThat(Packed, is(equal_to(ExpectedStructure))).
standard_request_creates_nested_iolist(_, _, Config) ->
- {ok, Xml} = file:read_file(filename:join(?config(data_dir, Config), "foo.xml")),
- {ok, Xsl} = file:read_file(filename:join(?config(data_dir, Config), "to_xml.xsl")),
+ Fixtures = ?config(fixtures, Config),
+ {ok, Xml} = file:read_file(?fixture(Config, "foo.xml")),
+ {ok, Xsl} = file:read_file(?fixture(Config, "to_xml.xsl")),
Packed = erlxsl_marshall:pack(<<"">>, ?FILE_INPUT, ?FILE_INPUT, Xml, Xsl),
Offset = ?NO_DIV_OFFSET,
InputKind = 1,
@@ -77,19 +77,29 @@ init_per_suite(C) ->
end_per_suite(_) ->
erlxsl_app:stop().
+init_per_testcase(_, Config) ->
+ DataDir = ?config(data_dir, Config),
+ Fixtures = test_support:get_fixture_dir(DataDir),
+ [{fixtures, Fixtures}|Config].
+
+end_per_testcase(_, _) ->
+ ok.
+
basic_transform(Config) ->
- {ok, Foo} = file:read_file(filename:join(?config(data_dir, Config), "foo.xml")),
+ {ok, Foo} = file:read_file(?fixture(Config, "foo.xml")),
X = erlxsl_port_controller:transform(Foo, <<"<output name='foo' age='21'/>">>),
ExpectedResult = binary_to_list(Foo) ++ binary_to_list(<<"<output name='foo' age='21'/>">>),
?assertThat(binary_to_list(X), equal_to(ExpectedResult)).
basic_transform_two_large_docs(Config) ->
- {ok, Xml} = file:read_file(filename:join(?config(data_dir, Config), "foo.xml")),
- {ok, Xsl} = file:read_file(filename:join(?config(data_dir, Config), "to_xml.xsl")),
- X = erlxsl_port_controller:transform(Xml, Xsl),
- ?assertThat(byte_size(X), equal_to(byte_size(Xml) + byte_size(Xsl))).
+ %% really just demonstrates handling a *reasonable* amount of data (in + out)
+ %% TODO: proper test case around *very large* inputs/output
+ %% TODO: streaming api support?
+ {ok, Xml} = file:read_file(?fixture(Config, "to_xml.xsl")),
+ X = erlxsl_port_controller:transform(Xml, Xml),
+ ?assertThat(byte_size(X), equal_to(byte_size(Xml) * 2)).
-bad_args_transform(Config) ->
+bad_args_transform(_) ->
X = erlxsl_port_controller:transform(bad, args),
?assertMatch({error, {function_clause,
[{erlxsl_marshall,pack,[_, buffer, buffer, bad, args]},
View
@@ -0,0 +1,7 @@
+-module(test_support).
+-compile(export_all).
+
+get_fixture_dir(DataDir) ->
+ SuiteData = filename:split(DataDir),
+ TestDir = filename:join(lists:sublist(SuiteData, length(SuiteData) - 1)),
+ filename:join(TestDir, "fixtures").

0 comments on commit 4f8325f

Please sign in to comment.