From 841addf5d64a3b4775cd1d0a5aa4bf04ec4ef95e Mon Sep 17 00:00:00 2001 From: Tobias Schlager Date: Tue, 18 Feb 2014 12:33:31 +0100 Subject: Add test suites performing app and appup file checks Add the mentioned test suites for *all* library and touched non-library applications. --- lib/percept/test/percept_SUITE.erl | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'lib/percept/test') diff --git a/lib/percept/test/percept_SUITE.erl b/lib/percept/test/percept_SUITE.erl index e415d92a04..aea2462b2e 100644 --- a/lib/percept/test/percept_SUITE.erl +++ b/lib/percept/test/percept_SUITE.erl @@ -27,6 +27,8 @@ %% Test cases -export([ + app/1, + appup/1, profile/1, analyze/1, analyze_dist/1, @@ -54,7 +56,7 @@ end_per_testcase(_Case, Config) -> suite() -> [{ct_hooks,[ts_install_cth]}]. all() -> - [webserver, profile, analyze, analyze_dist]. + [app, appup, webserver, profile, analyze, analyze_dist]. groups() -> []. @@ -70,6 +72,14 @@ end_per_group(_GroupName, Config) -> %% Tests %%---------------------------------------------------------------------- +%% Test that the percept app file is ok +app(Config) when is_list(Config) -> + ok = ?t:app_test(percept). + +%% Test that the percept appup file is ok +appup(Config) when is_list(Config) -> + ok = ?t:appup_test(percept). + webserver(suite) -> []; webserver(doc) -> -- cgit v1.2.3 From 738c34d4bb8f1a3811acd00af8c6c12107f8315b Mon Sep 17 00:00:00 2001 From: Bruce Yinhe Date: Thu, 18 Jun 2015 11:31:02 +0200 Subject: Change license text to APLv2 --- lib/percept/test/Makefile | 21 +++++++++++---------- lib/percept/test/egd_SUITE.erl | 19 ++++++++++--------- lib/percept/test/ipc_tree.erl | 21 +++++++++++---------- lib/percept/test/percept_SUITE.erl | 21 +++++++++++---------- lib/percept/test/percept_db_SUITE.erl | 19 ++++++++++--------- 5 files changed, 53 insertions(+), 48 deletions(-) (limited to 'lib/percept/test') diff --git a/lib/percept/test/Makefile b/lib/percept/test/Makefile index 156ef5dd0a..4ba0b80fc8 100644 --- a/lib/percept/test/Makefile +++ b/lib/percept/test/Makefile @@ -3,16 +3,17 @@ # # Copyright Ericsson AB 2007-2012. All Rights Reserved. # -# The contents of this file are subject to the Erlang Public License, -# Version 1.1, (the "License"); you may not use this file except in -# compliance with the License. You should have received a copy of the -# Erlang Public License along with this software. If not, it can be -# retrieved online at http://www.erlang.org/. -# -# Software distributed under the License is distributed on an "AS IS" -# basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See -# the License for the specific language governing rights and limitations -# under the License. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. # # %CopyrightEnd% # diff --git a/lib/percept/test/egd_SUITE.erl b/lib/percept/test/egd_SUITE.erl index 51f090b39c..41e8999e17 100644 --- a/lib/percept/test/egd_SUITE.erl +++ b/lib/percept/test/egd_SUITE.erl @@ -3,16 +3,17 @@ %% %% Copyright Ericsson AB 2007-2011. All Rights Reserved. %% -%% The contents of this file are subject to the Erlang Public License, -%% Version 1.1, (the "License"); you may not use this file except in -%% compliance with the License. You should have received a copy of the -%% Erlang Public License along with this software. If not, it can be -%% retrieved online at http://www.erlang.org/. +%% Licensed under the Apache License, Version 2.0 (the "License"); +%% you may not use this file except in compliance with the License. +%% You may obtain a copy of the License at %% -%% Software distributed under the License is distributed on an "AS IS" -%% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See -%% the License for the specific language governing rights and limitations -%% under the License. +%% http://www.apache.org/licenses/LICENSE-2.0 +%% +%% Unless required by applicable law or agreed to in writing, software +%% distributed under the License is distributed on an "AS IS" BASIS, +%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +%% See the License for the specific language governing permissions and +%% limitations under the License. %% %% %CopyrightEnd% %% diff --git a/lib/percept/test/ipc_tree.erl b/lib/percept/test/ipc_tree.erl index f7639eed1b..ff1c8d49c1 100644 --- a/lib/percept/test/ipc_tree.erl +++ b/lib/percept/test/ipc_tree.erl @@ -1,13 +1,14 @@ -%% ``The contents of this file are subject to the Erlang Public License, -%% Version 1.1, (the "License"); you may not use this file except in -%% compliance with the License. You should have received a copy of the -%% Erlang Public License along with this software. If not, it can be -%% retrieved via the world wide web at http://www.erlang.org/. -%% -%% Software distributed under the License is distributed on an "AS IS" -%% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See -%% the License for the specific language governing rights and limitations -%% under the License. +%% ``Licensed under the Apache License, Version 2.0 (the "License"); +%% you may not use this file except in compliance with the License. +%% You may obtain a copy of the License at +%% +%% http://www.apache.org/licenses/LICENSE-2.0 +%% +%% Unless required by applicable law or agreed to in writing, software +%% distributed under the License is distributed on an "AS IS" BASIS, +%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +%% See the License for the specific language governing permissions and +%% limitations under the License. %% %% The Initial Developer of the Original Code is Ericsson Utvecklings AB. %% Portions created by Ericsson are Copyright 1999, Ericsson Utvecklings diff --git a/lib/percept/test/percept_SUITE.erl b/lib/percept/test/percept_SUITE.erl index aea2462b2e..fd96c2b97a 100644 --- a/lib/percept/test/percept_SUITE.erl +++ b/lib/percept/test/percept_SUITE.erl @@ -3,16 +3,17 @@ %% %% Copyright Ericsson AB 2007-2011. All Rights Reserved. %% -%% The contents of this file are subject to the Erlang Public License, -%% Version 1.1, (the "License"); you may not use this file except in -%% compliance with the License. You should have received a copy of the -%% Erlang Public License along with this software. If not, it can be -%% retrieved online at http://www.erlang.org/. -%% -%% Software distributed under the License is distributed on an "AS IS" -%% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See -%% the License for the specific language governing rights and limitations -%% under the License. +%% Licensed under the Apache License, Version 2.0 (the "License"); +%% you may not use this file except in compliance with the License. +%% You may obtain a copy of the License at +%% +%% http://www.apache.org/licenses/LICENSE-2.0 +%% +%% Unless required by applicable law or agreed to in writing, software +%% distributed under the License is distributed on an "AS IS" BASIS, +%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +%% See the License for the specific language governing permissions and +%% limitations under the License. %% %% %CopyrightEnd% %% diff --git a/lib/percept/test/percept_db_SUITE.erl b/lib/percept/test/percept_db_SUITE.erl index 79be9714ba..e2775aabc0 100644 --- a/lib/percept/test/percept_db_SUITE.erl +++ b/lib/percept/test/percept_db_SUITE.erl @@ -3,16 +3,17 @@ %% %% Copyright Ericsson AB 2007-2010. All Rights Reserved. %% -%% The contents of this file are subject to the Erlang Public License, -%% Version 1.1, (the "License"); you may not use this file except in -%% compliance with the License. You should have received a copy of the -%% Erlang Public License along with this software. If not, it can be -%% retrieved online at http://www.erlang.org/. +%% Licensed under the Apache License, Version 2.0 (the "License"); +%% you may not use this file except in compliance with the License. +%% You may obtain a copy of the License at %% -%% Software distributed under the License is distributed on an "AS IS" -%% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See -%% the License for the specific language governing rights and limitations -%% under the License. +%% http://www.apache.org/licenses/LICENSE-2.0 +%% +%% Unless required by applicable law or agreed to in writing, software +%% distributed under the License is distributed on an "AS IS" BASIS, +%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +%% See the License for the specific language governing permissions and +%% limitations under the License. %% %% %CopyrightEnd% %% -- cgit v1.2.3 From 983642a38b3627425f77fc6f8b8ccd121fd41f52 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Gustavsson?= Date: Thu, 10 Dec 2015 13:18:20 +0100 Subject: percept tests: Replace 'random' with 'rand' --- lib/percept/test/egd_SUITE.erl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'lib/percept/test') diff --git a/lib/percept/test/egd_SUITE.erl b/lib/percept/test/egd_SUITE.erl index 41e8999e17..5a0a9af14d 100644 --- a/lib/percept/test/egd_SUITE.erl +++ b/lib/percept/test/egd_SUITE.erl @@ -40,7 +40,7 @@ -define(default_timeout, ?t:minutes(1)). init_per_suite(Config) when is_list(Config) -> - random:seed(now()), + rand:seed(exsplus), Config. end_per_suite(Config) when is_list(Config) -> @@ -348,4 +348,4 @@ get_points(0, Out) -> get_points(N, Out) -> get_points(N - 1, [get_point() | Out]). -random(N) -> trunc(random:uniform(trunc(N + 1)) - 1). +random(N) -> trunc(rand:uniform(trunc(N + 1)) - 1). -- cgit v1.2.3 From 03fcb7dabf8861e60ffab4121a909b347bccfec9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Gustavsson?= Date: Mon, 15 Feb 2016 15:33:12 +0100 Subject: Eliminate use of test_server.hrl and test_server_line.hrl As a first step to removing the test_server application as as its own separate application, change the inclusion of test_server.hrl to an inclusion of ct.hrl and remove the inclusion of test_server_line.hrl. --- lib/percept/test/egd_SUITE.erl | 2 +- lib/percept/test/percept_SUITE.erl | 2 +- lib/percept/test/percept_db_SUITE.erl | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) (limited to 'lib/percept/test') diff --git a/lib/percept/test/egd_SUITE.erl b/lib/percept/test/egd_SUITE.erl index 5a0a9af14d..0b1149e1f1 100644 --- a/lib/percept/test/egd_SUITE.erl +++ b/lib/percept/test/egd_SUITE.erl @@ -19,7 +19,7 @@ %% -module(egd_SUITE). --include_lib("test_server/include/test_server.hrl"). +-include_lib("common_test/include/ct.hrl"). %% Test server specific exports -export([all/0, suite/0,groups/0,init_per_group/2,end_per_group/2]). diff --git a/lib/percept/test/percept_SUITE.erl b/lib/percept/test/percept_SUITE.erl index fd96c2b97a..06d62630ba 100644 --- a/lib/percept/test/percept_SUITE.erl +++ b/lib/percept/test/percept_SUITE.erl @@ -19,7 +19,7 @@ %% -module(percept_SUITE). --include_lib("test_server/include/test_server.hrl"). +-include_lib("common_test/include/ct.hrl"). %% Test server specific exports -export([all/0, suite/0,groups/0,init_per_group/2,end_per_group/2]). diff --git a/lib/percept/test/percept_db_SUITE.erl b/lib/percept/test/percept_db_SUITE.erl index e2775aabc0..5b878e8462 100644 --- a/lib/percept/test/percept_db_SUITE.erl +++ b/lib/percept/test/percept_db_SUITE.erl @@ -19,7 +19,7 @@ %% -module(percept_db_SUITE). --include("test_server.hrl"). +-include_lib("common_test/include/ct.hrl"). %% Test server specific exports -export([all/1]). -- cgit v1.2.3 From 4e1162bbdf88465a03da165c088ad1256b816956 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Gustavsson?= Date: Mon, 15 Feb 2016 16:04:32 +0100 Subject: Makefiles: Remove test_server from include path and code path Since no test suites includede test_server.hrl, there is no need to have test_server in the include path or code path. --- lib/percept/test/Makefile | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'lib/percept/test') diff --git a/lib/percept/test/Makefile b/lib/percept/test/Makefile index 4ba0b80fc8..6891de832d 100644 --- a/lib/percept/test/Makefile +++ b/lib/percept/test/Makefile @@ -52,8 +52,7 @@ RELSYSDIR = $(RELEASE_PATH)/percept_test # FLAGS # ---------------------------------------------------- ERL_MAKE_FLAGS += -ERL_COMPILE_FLAGS += -I$(ERL_TOP)/lib/test_server/include \ - -I$(ERL_TOP)/lib/percept/include +ERL_COMPILE_FLAGS += -I$(ERL_TOP)/lib/percept/include # ---------------------------------------------------- # Targets -- cgit v1.2.3 From 6664eed554974336909d3ffe03f20349cc4c38fd Mon Sep 17 00:00:00 2001 From: Henrik Nord Date: Tue, 15 Mar 2016 15:19:56 +0100 Subject: update copyright-year --- lib/percept/test/Makefile | 2 +- lib/percept/test/egd_SUITE.erl | 2 +- lib/percept/test/percept_SUITE.erl | 2 +- lib/percept/test/percept_db_SUITE.erl | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) (limited to 'lib/percept/test') diff --git a/lib/percept/test/Makefile b/lib/percept/test/Makefile index 6891de832d..87fde49410 100644 --- a/lib/percept/test/Makefile +++ b/lib/percept/test/Makefile @@ -1,7 +1,7 @@ # # %CopyrightBegin% # -# Copyright Ericsson AB 2007-2012. All Rights Reserved. +# Copyright Ericsson AB 2007-2016. All Rights Reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/lib/percept/test/egd_SUITE.erl b/lib/percept/test/egd_SUITE.erl index 0b1149e1f1..65c942f1e4 100644 --- a/lib/percept/test/egd_SUITE.erl +++ b/lib/percept/test/egd_SUITE.erl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 2007-2011. All Rights Reserved. +%% Copyright Ericsson AB 2007-2016. All Rights Reserved. %% %% Licensed under the Apache License, Version 2.0 (the "License"); %% you may not use this file except in compliance with the License. diff --git a/lib/percept/test/percept_SUITE.erl b/lib/percept/test/percept_SUITE.erl index 06d62630ba..b771f9ec3a 100644 --- a/lib/percept/test/percept_SUITE.erl +++ b/lib/percept/test/percept_SUITE.erl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 2007-2011. All Rights Reserved. +%% Copyright Ericsson AB 2007-2016. All Rights Reserved. %% %% Licensed under the Apache License, Version 2.0 (the "License"); %% you may not use this file except in compliance with the License. diff --git a/lib/percept/test/percept_db_SUITE.erl b/lib/percept/test/percept_db_SUITE.erl index 5b878e8462..d4f732fb1c 100644 --- a/lib/percept/test/percept_db_SUITE.erl +++ b/lib/percept/test/percept_db_SUITE.erl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 2007-2010. All Rights Reserved. +%% Copyright Ericsson AB 2007-2016. All Rights Reserved. %% %% Licensed under the Apache License, Version 2.0 (the "License"); %% you may not use this file except in compliance with the License. -- cgit v1.2.3 From e7473f6810b249d1115361f005fb8b44fe59f474 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn-Egil=20Dahlberg?= Date: Wed, 16 Mar 2016 18:36:18 +0100 Subject: Use monotonic_time/1 instead of now/0 --- lib/percept/test/percept_SUITE.erl | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) (limited to 'lib/percept/test') diff --git a/lib/percept/test/percept_SUITE.erl b/lib/percept/test/percept_SUITE.erl index 06d62630ba..afb8bbdd5b 100644 --- a/lib/percept/test/percept_SUITE.erl +++ b/lib/percept/test/percept_SUITE.erl @@ -116,11 +116,10 @@ analyze(Config) when is_list(Config) -> Begin = processes(), Path = ?config(data_dir, Config), File = filename:join([Path,"profile_test.dat"]), - T0 = erlang:now(), + T0 = erlang:monotonic_time(milli_seconds), ?line ok = percept:analyze(File), - T1 = erlang:now(), - Secs = timer:now_diff(T1,T0)/1000000, - io:format("percept:analyze/1 took ~.2f s.~n", [Secs]), + T1 = erlang:monotonic_time(milli_seconds), + io:format("percept:analyze/1 took ~w ms.~n", [T1 - T0]), ?line {stopped, _} = percept_db:stop(), print_remainers(remainers(Begin, processes())), ok. @@ -133,11 +132,10 @@ analyze_dist(Config) when is_list(Config) -> Begin = processes(), Path = ?config(data_dir, Config), File = filename:join([Path,"ipc-dist.dat"]), - T0 = erlang:now(), + T0 = erlang:monotonic_time(milli_seconds), ?line ok = percept:analyze(File), - T1 = erlang:now(), - Secs = timer:now_diff(T1,T0)/1000000, - io:format("percept:analyze/1 took ~.2f s.~n", [Secs]), + T1 = erlang:monotonic_time(milli_seconds), + io:format("percept:analyze/1 took ~w ms.~n", [T1 - T0]), ?line {stopped, _} = percept_db:stop(), print_remainers(remainers(Begin, processes())), ok. -- cgit v1.2.3 From 86743354292ef497401303b6e8566b6f3f738b96 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn-Egil=20Dahlberg?= Date: Wed, 16 Mar 2016 19:02:13 +0100 Subject: Modernize test suites --- lib/percept/test/egd_SUITE.erl | 336 +++++++++++++++------------------- lib/percept/test/ipc_tree.erl | 2 +- lib/percept/test/percept_SUITE.erl | 114 ++++-------- lib/percept/test/percept_db_SUITE.erl | 36 +--- 4 files changed, 191 insertions(+), 297 deletions(-) (limited to 'lib/percept/test') diff --git a/lib/percept/test/egd_SUITE.erl b/lib/percept/test/egd_SUITE.erl index 0b1149e1f1..6df7ed74c0 100644 --- a/lib/percept/test/egd_SUITE.erl +++ b/lib/percept/test/egd_SUITE.erl @@ -22,195 +22,160 @@ -include_lib("common_test/include/ct.hrl"). %% Test server specific exports --export([all/0, suite/0,groups/0,init_per_group/2,end_per_group/2]). +-export([all/0, suite/0]). -export([init_per_suite/1, end_per_suite/1]). -export([init_per_testcase/2, end_per_testcase/2]). %% Test cases --export([ - image_create_and_destroy/1, - image_shape/1, - image_primitives/1, - image_colors/1, - image_font/1, - image_png_compliant/1 - ]). - -%% Default timetrap timeout (set in init_per_testcase) --define(default_timeout, ?t:minutes(1)). +-export([image_create_and_destroy/1, + image_shape/1, + image_primitives/1, + image_colors/1, + image_font/1, + image_png_compliant/1]). -init_per_suite(Config) when is_list(Config) -> - rand:seed(exsplus), - Config. - -end_per_suite(Config) when is_list(Config) -> - Config. - -init_per_testcase(_Case, Config) -> - Dog = ?t:timetrap(?default_timeout), - [{max_size, 800}, {watchdog,Dog} | Config]. - -end_per_testcase(_Case, Config) -> - Dog = ?config(watchdog, Config), - ?t:timetrap_cancel(Dog), - ok. - -suite() -> [{ct_hooks,[ts_install_cth]}]. +suite() -> + [{ct_hooks,[ts_install_cth]}, + {timetrap, {minutes, 1}}]. all() -> [image_create_and_destroy, image_shape, image_primitives, image_colors, image_font, image_png_compliant]. -groups() -> - []. -init_per_group(_GroupName, Config) -> +init_per_suite(Config) when is_list(Config) -> + rand:seed(exsplus), Config. -end_per_group(_GroupName, Config) -> +end_per_suite(Config) when is_list(Config) -> Config. +init_per_testcase(_Case, Config) -> + [{max_size, 800}|Config]. + +end_per_testcase(_Case, _Config) -> + ok. %%---------------------------------------------------------------------- %% Tests %%---------------------------------------------------------------------- -image_create_and_destroy(suite) -> - []; -image_create_and_destroy(doc) -> - ["Image creation and destroy test."]; +%% Image creation and destroy test. image_create_and_destroy(Config) when is_list(Config) -> - {W,H} = get_size(?config(max_size, Config)), - ?line Image = egd:create(W, H), - ?line ok = egd:destroy(Image), + {W,H} = get_size(proplists:get_value(max_size, Config)), + Image = egd:create(W, H), + ok = egd:destroy(Image), ok. -image_colors(suite) -> - []; -image_colors(doc) -> - ["Image color test."]; +%% Image color test. image_colors(Config) when is_list(Config) -> - {W,H} = get_size(?config(max_size, Config)), - ?line Image = egd:create(W, H), + {W,H} = get_size(proplists:get_value(max_size, Config)), + Image = egd:create(W, H), put(image_size, {W,H}), RGB = get_rgb(), - ?line Black = egd:color({0,0,0}), - ?line Red = egd:color({255,0,0}), - ?line Green = egd:color({0,255,0}), - ?line Blue = egd:color({0,0,255}), - ?line Random = egd:color(Image, RGB), - - ?line ok = egd:line(Image, get_point(), get_point(), Random), - ?line ok = egd:line(Image, get_point(), get_point(), Red), - ?line ok = egd:line(Image, get_point(), get_point(), Green), - ?line ok = egd:line(Image, get_point(), get_point(), Black), - ?line ok = egd:line(Image, get_point(), get_point(), Blue), + Black = egd:color({0,0,0}), + Red = egd:color({255,0,0}), + Green = egd:color({0,255,0}), + Blue = egd:color({0,0,255}), + Random = egd:color(Image, RGB), + + ok = egd:line(Image, get_point(), get_point(), Random), + ok = egd:line(Image, get_point(), get_point(), Red), + ok = egd:line(Image, get_point(), get_point(), Green), + ok = egd:line(Image, get_point(), get_point(), Black), + ok = egd:line(Image, get_point(), get_point(), Blue), HtmlDefaultNames = [black,silver,gray,white,maroon,red, - purple,fuchia,green,lime,olive,yellow,navy,blue,teal, - aqua], - - lists:foreach(fun - (ColorName) -> - ?line Color = egd:color(ColorName), - ?line ok = egd:line(Image, get_point(), get_point(), Color) - end, HtmlDefaultNames), - - ?line <<_/binary>> = egd:render(Image), - ?line ok = egd:destroy(Image), + purple,fuchia,green,lime,olive,yellow,navy,blue,teal, + aqua], + + lists:foreach(fun (ColorName) -> + Color = egd:color(ColorName), + ok = egd:line(Image, get_point(), get_point(), Color) + end, HtmlDefaultNames), + + <<_/binary>> = egd:render(Image), + ok = egd:destroy(Image), erase(image_size), ok. -image_shape(suite) -> - []; -image_shape(doc) -> - ["Image shape api test."]; +%% Image shape API test. image_shape(Config) when is_list(Config) -> - {W,H} = get_size(?config(max_size, Config)), + {W,H} = get_size(proplists:get_value(max_size, Config)), put(image_size, {W,H}), - ?line Im = egd:create(W, H), - - ?line Fgc = egd:color({255,0,0}), - - ?line ok = egd:line(Im, get_point(), get_point(), Fgc), - ?line ok = egd:rectangle(Im, get_point(), get_point(), Fgc), - ?line ok = egd:filledEllipse(Im, get_point(), get_point(), Fgc), - ?line ok = egd:arc(Im, get_point(), get_point(), Fgc), - ?line ok = egd:arc(Im, get_point(), get_point(), 100, Fgc), - + Im = egd:create(W, H), + + Fgc = egd:color({255,0,0}), + + ok = egd:line(Im, get_point(), get_point(), Fgc), + ok = egd:rectangle(Im, get_point(), get_point(), Fgc), + ok = egd:filledEllipse(Im, get_point(), get_point(), Fgc), + ok = egd:arc(Im, get_point(), get_point(), Fgc), + ok = egd:arc(Im, get_point(), get_point(), 100, Fgc), + Pt1 = get_point(), Pt2 = get_point(), - ?line ok = egd:filledRectangle(Im, Pt1, Pt2, Fgc), + ok = egd:filledRectangle(Im, Pt1, Pt2, Fgc), - ?line Bitmap = egd:render(Im, raw_bitmap), + Bitmap = egd:render(Im, raw_bitmap), - ?line ok = bitmap_point_has_color(Bitmap, {W,H}, Pt2, Fgc), - ?line ok = bitmap_point_has_color(Bitmap, {W,H}, Pt1, Fgc), + ok = bitmap_point_has_color(Bitmap, {W,H}, Pt2, Fgc), + ok = bitmap_point_has_color(Bitmap, {W,H}, Pt1, Fgc), - ?line <<_/binary>> = egd:render(Im, raw_bitmap, [{render_engine, alpha}]), + <<_/binary>> = egd:render(Im, raw_bitmap, [{render_engine, alpha}]), - ?line ok = egd:destroy(Im), + ok = egd:destroy(Im), erase(image_size), ok. -image_primitives(suite) -> - []; -image_primitives(doc) -> - ["Image shape api test."]; +%% Image shape API test. image_primitives(Config) when is_list(Config) -> - {W,H} = get_size(?config(max_size, Config)), + {W,H} = get_size(proplists:get_value(max_size, Config)), put(image_size, {W,H}), - ?line Im0 = egd_primitives:create(W, H), - ?line Fgc = egd:color({25,25,255}), - ?line Bgc = egd:color({0,250,25}), + Im0 = egd_primitives:create(W, H), + Fgc = egd:color({25,25,255}), + Bgc = egd:color({0,250,25}), - ?line Im1 = lists:foldl(fun - ({Function, Arguments}, Im) -> - ?line erlang:apply(egd_primitives, Function, [Im|Arguments]) - end, Im0, - [{Fs, [get_point(), get_point(), Bgc]} || Fs <- [line, rectangle, filledEllipse, arc]] ++ - [{pixel, [get_point(), Bgc]}, - {filledTriangle, [get_point(), get_point(), get_point(), Bgc]}]), + Im1 = lists:foldl(fun ({Function, Arguments}, Im) -> + erlang:apply(egd_primitives, Function, [Im|Arguments]) + end, Im0, + [{Fs, [get_point(), get_point(), Bgc]} || Fs <- [line, rectangle, filledEllipse, arc]] ++ + [{pixel, [get_point(), Bgc]}, + {filledTriangle, [get_point(), get_point(), get_point(), Bgc]}]), Pt1 = get_point(), Pt2 = get_point(), - ?line Im2 = egd_primitives:filledRectangle(Im1, Pt1, Pt2, Fgc), + Im2 = egd_primitives:filledRectangle(Im1, Pt1, Pt2, Fgc), - ?line Bitmap = egd_render:binary(Im2, opaque), + Bitmap = egd_render:binary(Im2, opaque), - ?line ok = bitmap_point_has_color(Bitmap, {W,H}, Pt2, Fgc), - ?line ok = bitmap_point_has_color(Bitmap, {W,H}, Pt1, Fgc), + ok = bitmap_point_has_color(Bitmap, {W,H}, Pt2, Fgc), + ok = bitmap_point_has_color(Bitmap, {W,H}, Pt1, Fgc), - ?line <<_/binary>> = egd_render:binary(Im2, alpha), + <<_/binary>> = egd_render:binary(Im2, alpha), erase(image_size), ok. - - - -image_font(suite) -> - []; -image_font(doc) -> - ["Image font test."]; +%% Image font test. image_font(Config) when is_list(Config) -> - {W,H} = get_size(?config(max_size, Config)), + {W,H} = get_size(proplists:get_value(max_size, Config)), put(image_size, {W,H}), - ?line Im = egd:create(W, H), - ?line Fgc = egd:color({0,130,0}), - - ?line Filename = filename:join([code:priv_dir(percept),"fonts","6x11_latin1.wingsfont"]), - ?line Font = egd_font:load(Filename), - + Im = egd:create(W, H), + Fgc = egd:color({0,130,0}), + + Filename = filename:join([code:priv_dir(percept),"fonts","6x11_latin1.wingsfont"]), + Font = egd_font:load(Filename), + % simple text - ?line ok = egd:text(Im, get_point(), Font, "Hello World", Fgc), - ?line <<_/binary>> = egd:render(Im, png), - + ok = egd:text(Im, get_point(), Font, "Hello World", Fgc), + <<_/binary>> = egd:render(Im, png), + GlyphStr1 = " !\"#$%&'()*+,-./", % Codes 32 -> 47 NumericStr = "0123456789", % Codes 48 -> 57 GlyphStr2 = ":;<=>?@", % Codes 58 -> 64 @@ -219,62 +184,59 @@ image_font(Config) when is_list(Config) -> AlphaSmStr = "abcdefghijklmnopqrstuvwxyz", % Codes 97 -> 122 GlyphStr4 = "{|}~", % Codes 123 -> 126 - ?line ok = egd:text(Im, get_point(), Font, GlyphStr1, Fgc), - ?line <<_/binary>> = egd:render(Im, png), + ok = egd:text(Im, get_point(), Font, GlyphStr1, Fgc), + <<_/binary>> = egd:render(Im, png), + + ok = egd:text(Im, get_point(), Font, NumericStr, Fgc), + <<_/binary>> = egd:render(Im, png), + + ok = egd:text(Im, get_point(), Font, GlyphStr2, Fgc), + <<_/binary>> = egd:render(Im, png), + + ok = egd:text(Im, get_point(), Font, AlphaBigStr, Fgc), + <<_/binary>> = egd:render(Im, png), - ?line ok = egd:text(Im, get_point(), Font, NumericStr, Fgc), - ?line <<_/binary>> = egd:render(Im, png), - - ?line ok = egd:text(Im, get_point(), Font, GlyphStr2, Fgc), - ?line <<_/binary>> = egd:render(Im, png), + ok = egd:text(Im, get_point(), Font, GlyphStr3, Fgc), + <<_/binary>> = egd:render(Im, png), - ?line ok = egd:text(Im, get_point(), Font, AlphaBigStr, Fgc), - ?line <<_/binary>> = egd:render(Im, png), - - ?line ok = egd:text(Im, get_point(), Font, GlyphStr3, Fgc), - ?line <<_/binary>> = egd:render(Im, png), + ok = egd:text(Im, get_point(), Font, AlphaSmStr, Fgc), + <<_/binary>> = egd:render(Im, png), - ?line ok = egd:text(Im, get_point(), Font, AlphaSmStr, Fgc), - ?line <<_/binary>> = egd:render(Im, png), - - ?line ok = egd:text(Im, get_point(), Font, GlyphStr4, Fgc), - ?line <<_/binary>> = egd:render(Im, png), + ok = egd:text(Im, get_point(), Font, GlyphStr4, Fgc), + <<_/binary>> = egd:render(Im, png), - ?line ok = egd:destroy(Im), + ok = egd:destroy(Im), erase(image_size), ok. -image_png_compliant(suite) -> - []; -image_png_compliant(doc) -> - ["Image png compliant test."]; +%% Image png compliant test. image_png_compliant(Config) when is_list(Config) -> - {W,H} = get_size(?config(max_size, Config)), + {W,H} = get_size(proplists:get_value(max_size, Config)), put(image_size, {W,H}), - ?line Im = egd:create(W, H), - ?line Fgc = egd:color({0,0,0}), - ?line ok = egd:filledRectangle(Im, get_point(), get_point(), Fgc), - - ?line Bin = egd:render(Im, png), - ?line true = binary_is_png_compliant(Bin), - - ?line ok = egd:destroy(Im), + Im = egd:create(W, H), + Fgc = egd:color({0,0,0}), + ok = egd:filledRectangle(Im, get_point(), get_point(), Fgc), + + Bin = egd:render(Im, png), + true = binary_is_png_compliant(Bin), + + ok = egd:destroy(Im), erase(image_size), ok. %%---------------------------------------------------------------------- %% Auxiliary tests %%---------------------------------------------------------------------- - + bitmap_point_has_color(Bitmap, {W,_}, {X,Y}, C) -> {CR,CG,CB,_} = egd_primitives:rgb_float2byte(C), N = W*Y*3 + X*3, << _:N/binary, R,G,B, _/binary>> = Bitmap, case {R,G,B} of - {CR,CG,CB} -> ok; - Other -> - io:format("bitmap_point_has_color: error color was ~p, should be ~p~n", [Other, {CR,CG,CB}]), - {error, {Other,{CR,CG,CB}}} + {CR,CG,CB} -> ok; + Other -> + io:format("bitmap_point_has_color: error color was ~p, should be ~p~n", [Other, {CR,CG,CB}]), + {error, {Other,{CR,CG,CB}}} end. %% jfif header by specification @@ -283,35 +245,35 @@ bitmap_point_has_color(Bitmap, {W,_}, {X,Y}, C) -> %% 2 bytes, version, (major, minor) %% 1 byte , units %% However, JFIF seems to start at 6 (7 with 1-index)? - + binary_is_jfif_compliant(JpegBin) -> - ?line {Bin, _} = split_binary(JpegBin, 11), + {Bin, _} = split_binary(JpegBin, 11), List = binary_to_list(Bin), case lists:sublist(List, 7, 4) of - "JFIF" -> true; - Other -> - io:format("img -> ~p~n", [Other]), - false + "JFIF" -> true; + Other -> + io:format("img -> ~p~n", [Other]), + false end. binary_is_gif_compliant(GifBin) -> - ?line {Bin, _} = split_binary(GifBin, 10), + {Bin, _} = split_binary(GifBin, 10), List = binary_to_list(Bin), case lists:sublist(List, 1,5) of - "GIF87" -> true; - Other -> - io:format("img -> ~p~n", [Other]), - false + "GIF87" -> true; + Other -> + io:format("img -> ~p~n", [Other]), + false end. binary_is_png_compliant(PngBin) -> - ?line {Bin, _} = split_binary(PngBin, 10), + {Bin, _} = split_binary(PngBin, 10), List = binary_to_list(Bin), case lists:sublist(List, 2,3) of - "PNG" -> true; - Other -> - io:format("img -> ~p~n", [Other]), - false + "PNG" -> true; + Other -> + io:format("img -> ~p~n", [Other]), + false end. %%---------------------------------------------------------------------- @@ -320,20 +282,20 @@ binary_is_png_compliant(PngBin) -> get_rgb() -> - R = random(255), - G = random(255), - B = random(255), - {R,G,B}. + R = random(255), + G = random(255), + B = random(255), + {R,G,B}. get_angle() -> - random(359). + random(359). get_point() -> get_point(get(image_size)). get_point({W,H}) -> - X = random(W - 1), - Y = random(H - 1), - {X,Y}. + X = random(W - 1), + Y = random(H - 1), + {X,Y}. get_size(Max) -> W = trunc(random(Max/2) + Max/2 + 1), @@ -344,7 +306,7 @@ get_size(Max) -> get_points(N) -> get_points(N, []). get_points(0, Out) -> - Out; + Out; get_points(N, Out) -> get_points(N - 1, [get_point() | Out]). diff --git a/lib/percept/test/ipc_tree.erl b/lib/percept/test/ipc_tree.erl index ff1c8d49c1..29da20e83f 100644 --- a/lib/percept/test/ipc_tree.erl +++ b/lib/percept/test/ipc_tree.erl @@ -46,4 +46,4 @@ gather([]) -> ok; gather([_|Pids]) -> receive _ -> gather(Pids) end. workload(0) -> ok; -workload(N) -> math:sin(2), workload(N - 1). +workload(N) -> _ = math:sin(2), workload(N - 1). diff --git a/lib/percept/test/percept_SUITE.erl b/lib/percept/test/percept_SUITE.erl index afb8bbdd5b..141035c631 100644 --- a/lib/percept/test/percept_SUITE.erl +++ b/lib/percept/test/percept_SUITE.erl @@ -22,51 +22,23 @@ -include_lib("common_test/include/ct.hrl"). %% Test server specific exports --export([all/0, suite/0,groups/0,init_per_group/2,end_per_group/2]). --export([init_per_suite/1, end_per_suite/1]). --export([init_per_testcase/2, end_per_testcase/2]). +-export([all/0, suite/0]). %% Test cases --export([ - app/1, - appup/1, - profile/1, - analyze/1, - analyze_dist/1, - webserver/1 - ]). - -%% Default timetrap timeout (set in init_per_testcase) --define(default_timeout, ?t:minutes(2)). - -init_per_suite(Config) when is_list(Config) -> - Config. - -end_per_suite(Config) when is_list(Config) -> - Config. - -init_per_testcase(_Case, Config) -> - Dog = ?t:timetrap(?default_timeout), - [{max_size, 300}, {watchdog,Dog} | Config]. - -end_per_testcase(_Case, Config) -> - Dog = ?config(watchdog, Config), - ?t:timetrap_cancel(Dog), - ok. +-export([app/1, + appup/1, + profile/1, + analyze/1, + analyze_dist/1, + webserver/1]). -suite() -> [{ct_hooks,[ts_install_cth]}]. +suite() -> + [{ct_hooks,[ts_install_cth]}, + {timetrap, {minutes, 2}}]. all() -> - [app, appup, webserver, profile, analyze, analyze_dist]. - -groups() -> - []. - -init_per_group(_GroupName, Config) -> - Config. - -end_per_group(_GroupName, Config) -> - Config. + [app, appup, webserver, profile, + analyze, analyze_dist]. %%---------------------------------------------------------------------- @@ -75,68 +47,56 @@ end_per_group(_GroupName, Config) -> %% Test that the percept app file is ok app(Config) when is_list(Config) -> - ok = ?t:app_test(percept). + ok = test_server:app_test(percept). %% Test that the percept appup file is ok appup(Config) when is_list(Config) -> - ok = ?t:appup_test(percept). + ok = test_server:appup_test(percept). -webserver(suite) -> - []; -webserver(doc) -> - ["Percept webserver test."]; +%% Percept webserver test. webserver(Config) when is_list(Config) -> % Explicit start inets? - ?line {started, _, Port} = percept:start_webserver(), - ?line ok = percept:stop_webserver(Port), - ?line {started, _, _} = percept:start_webserver(), - ?line ok = percept:stop_webserver(), - ?line {started, _, NewPort} = percept:start_webserver(), - ?line ok = percept:stop_webserver(NewPort), - ?line application:stop(inets), + {started, _, Port} = percept:start_webserver(), + ok = percept:stop_webserver(Port), + {started, _, _} = percept:start_webserver(), + ok = percept:stop_webserver(), + {started, _, NewPort} = percept:start_webserver(), + ok = percept:stop_webserver(NewPort), + application:stop(inets), ok. -profile(suite) -> - []; -profile(doc) -> - ["Percept profile test."]; +%% Percept profile test. profile(Config) when is_list(Config) -> - Path = ?config(data_dir, Config), + Path = proplists:get_value(data_dir, Config), File = filename:join([Path,"profile_test.dat"]), - ?line {ok, _} = percept:profile(File, [procs]), + {ok, _} = percept:profile(File, [procs]), ipc_tree:go(7), - ?line ok = percept:stop_profile(), + ok = percept:stop_profile(), ok. -analyze(suite) -> - []; -analyze(doc) -> - ["Percept analyze test."]; +%% Percept analyze test. analyze(Config) when is_list(Config) -> Begin = processes(), - Path = ?config(data_dir, Config), + Path = proplists:get_value(data_dir, Config), File = filename:join([Path,"profile_test.dat"]), T0 = erlang:monotonic_time(milli_seconds), - ?line ok = percept:analyze(File), + ok = percept:analyze(File), T1 = erlang:monotonic_time(milli_seconds), io:format("percept:analyze/1 took ~w ms.~n", [T1 - T0]), - ?line {stopped, _} = percept_db:stop(), + {stopped, _} = percept_db:stop(), print_remainers(remainers(Begin, processes())), ok. -analyze_dist(suite) -> - []; -analyze_dist(doc) -> - ["Percept analyze distribution test."]; +%% Percept analyze distribution test. analyze_dist(Config) when is_list(Config) -> Begin = processes(), - Path = ?config(data_dir, Config), + Path = proplists:get_value(data_dir, Config), File = filename:join([Path,"ipc-dist.dat"]), T0 = erlang:monotonic_time(milli_seconds), - ?line ok = percept:analyze(File), + ok = percept:analyze(File), T1 = erlang:monotonic_time(milli_seconds), io:format("percept:analyze/1 took ~w ms.~n", [T1 - T0]), - ?line {stopped, _} = percept_db:stop(), + {stopped, _} = percept_db:stop(), print_remainers(remainers(Begin, processes())), ok. @@ -164,9 +124,3 @@ remainers(Begin, [Pid|End], Out) -> true -> remainers(Begin, End, Out); false -> remainers(Begin, End, [Pid|Out]) end. - - - - - - diff --git a/lib/percept/test/percept_db_SUITE.erl b/lib/percept/test/percept_db_SUITE.erl index 5b878e8462..c1d711060c 100644 --- a/lib/percept/test/percept_db_SUITE.erl +++ b/lib/percept/test/percept_db_SUITE.erl @@ -22,54 +22,32 @@ -include_lib("common_test/include/ct.hrl"). %% Test server specific exports --export([all/1]). --export([init_per_suite/1, end_per_suite/1]). --export([init_per_testcase/2, end_per_testcase/2]). +-export([all/0, suite/0]). %% Test cases --export([ - start/1 - ]). +-export([start/1]). %% Default timetrap timeout (set in init_per_testcase) --define(default_timeout, ?t:minutes(2)). -define(restarts, 10). -define(alive_timeout, 500). -init_per_suite(Config) when is_list(Config) -> - Config. +suite() -> + [{timetrap, {minutes, 2}}]. -end_per_suite(Config) when is_list(Config) -> - Config. - -init_per_testcase(_Case, Config) -> - Dog = ?t:timetrap(?default_timeout), - [{max_size, 300}, {watchdog,Dog} | Config]. - -end_per_testcase(_Case, Config) -> - Dog = ?config(watchdog, Config), - ?t:timetrap_cancel(Dog), - ok. - -all(suite) -> - % Test cases +all() -> [start]. %%---------------------------------------------------------------------- %% Tests %%---------------------------------------------------------------------- -start(suite) -> - []; -start(doc) -> - ["Percept_db start and restart test."]; +%% Percept_db start and restart test. start(Config) when is_list(Config) -> ok = restart(?restarts), {stopped, _DB} = percept_db:stop(), ok. -restart(0)-> - ok; +restart(0)-> ok; restart(N)-> {_, DB} = percept_db:start(), timer:sleep(?alive_timeout), -- cgit v1.2.3 From 16ca699226aab43871506572d1a9221895260ab6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn-Egil=20Dahlberg?= Date: Sat, 14 May 2016 22:10:55 +0200 Subject: egd: Add more line tests Add images to common_test logs. --- lib/percept/test/egd_SUITE.erl | 46 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) (limited to 'lib/percept/test') diff --git a/lib/percept/test/egd_SUITE.erl b/lib/percept/test/egd_SUITE.erl index 3562ceae88..98a265ce61 100644 --- a/lib/percept/test/egd_SUITE.erl +++ b/lib/percept/test/egd_SUITE.erl @@ -32,6 +32,7 @@ image_primitives/1, image_colors/1, image_font/1, + image_fans/1, image_png_compliant/1]). suite() -> @@ -41,6 +42,7 @@ suite() -> all() -> [image_create_and_destroy, image_shape, image_primitives, image_colors, image_font, + image_fans, image_png_compliant]. @@ -224,6 +226,50 @@ image_png_compliant(Config) when is_list(Config) -> erase(image_size), ok. +image_fans(Config) when is_list(Config) -> + W = 1024, + H = 800, + Dir = proplists:get_value(priv_dir, Config), + + Fun = fun({F,Args},Im) -> + erlang:apply(egd_primitives,F,[Im|Args]) + end, + + %% fan1 + Ops1 = gen_vertical_fan(1,{0,400},egd:color(red),1024,800,-15), + Ops2 = gen_horizontal_fan(1,{512,800},egd:color(green),1024,0,-15), + + Im0 = egd_primitives:create(W,H), + Im1 = lists:foldl(Fun, Im0, Ops1 ++ Ops2), + Bin1 = egd_render:binary(Im1, opaque), + Png1 = egd_png:binary(W,H,Bin1), + + File1 = filename:join(Dir,"fan1.png"), + egd:save(Png1,File1), + ct:log("

Image1:

~n", [File1]), + + %% fan2 + Ops3 = gen_vertical_fan(7,{0,400},egd:color(red),1024,800,-15), + Ops4 = gen_horizontal_fan(7,{512,800},egd:color(green),1024,0,-15), + + Im2 = lists:foldl(Fun, Im0, Ops3 ++ Ops4), + Bin2 = egd_render:binary(Im2, opaque), + Png2 = egd_png:binary(W,H,Bin2), + + File2 = filename:join(Dir,"fan2.png"), + egd:save(Png2,File2), + ct:log("

Image2:

~n", [File2]), + ok. + +gen_vertical_fan(Wd,Pt,C,X,Y,Step) when Y > 0 -> + [{line,[Pt,{X,Y},Wd,C]}|gen_vertical_fan(Wd,Pt,C,X,Y + Step,Step)]; +gen_vertical_fan(_,_,_,_,_,_) -> []. + +gen_horizontal_fan(Wd,Pt,C,X,Y,Step) when X > 0 -> + [{line,[Pt,{X,Y},Wd,C]}|gen_horizontal_fan(Wd,Pt,C,X + Step,Y,Step)]; +gen_horizontal_fan(_,_,_,_,_,_) -> []. + + %%---------------------------------------------------------------------- %% Auxiliary tests %%---------------------------------------------------------------------- -- cgit v1.2.3 From 461867bc4ad264680af816e0e633e48bca2f17b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn-Egil=20Dahlberg?= Date: Sun, 15 May 2016 00:35:00 +0200 Subject: egd: Save images during tests --- lib/percept/test/egd_SUITE.erl | 120 +++++++++++++++++++++++++---------------- 1 file changed, 75 insertions(+), 45 deletions(-) (limited to 'lib/percept/test') diff --git a/lib/percept/test/egd_SUITE.erl b/lib/percept/test/egd_SUITE.erl index 98a265ce61..401695dddd 100644 --- a/lib/percept/test/egd_SUITE.erl +++ b/lib/percept/test/egd_SUITE.erl @@ -73,6 +73,7 @@ image_create_and_destroy(Config) when is_list(Config) -> %% Image color test. image_colors(Config) when is_list(Config) -> {W,H} = get_size(proplists:get_value(max_size, Config)), + Dir = proplists:get_value(priv_dir, Config), Image = egd:create(W, H), put(image_size, {W,H}), @@ -98,7 +99,15 @@ image_colors(Config) when is_list(Config) -> ok = egd:line(Image, get_point(), get_point(), Color) end, HtmlDefaultNames), - <<_/binary>> = egd:render(Image), + Png1 = <<_/binary>> = egd:render(Image,png,[{render_engine, alpha}]), + File1 = filename:join(Dir,"image_colors_alpha.png"), + ok = egd:save(Png1,File1), + ct:log("

Image alpha:

~n", [File1]), + Png2 = <<_/binary>> = egd:render(Image,png,[{render_engine, opaque}]), + File2 = filename:join(Dir,"image_colors_opaque.png"), + ok = egd:save(Png2,File2), + ct:log("

Image opaque:

~n", [File2]), + ok = egd:destroy(Image), erase(image_size), ok. @@ -106,6 +115,7 @@ image_colors(Config) when is_list(Config) -> %% Image shape API test. image_shape(Config) when is_list(Config) -> {W,H} = get_size(proplists:get_value(max_size, Config)), + Dir = proplists:get_value(priv_dir, Config), put(image_size, {W,H}), Im = egd:create(W, H), @@ -127,15 +137,21 @@ image_shape(Config) when is_list(Config) -> ok = bitmap_point_has_color(Bitmap, {W,H}, Pt2, Fgc), ok = bitmap_point_has_color(Bitmap, {W,H}, Pt1, Fgc), - <<_/binary>> = egd:render(Im, raw_bitmap, [{render_engine, alpha}]), + Bin = <<_/binary>> = egd:render(Im, raw_bitmap, [{render_engine, alpha}]), + Png = egd_png:binary(W,H,Bin), + File = filename:join(Dir,"image_shape.png"), + ok = egd:save(Png,File), + ct:log("

Image:

~n", [File]), ok = egd:destroy(Im), + erase(image_size), ok. %% Image shape API test. image_primitives(Config) when is_list(Config) -> {W,H} = get_size(proplists:get_value(max_size, Config)), + Dir = proplists:get_value(priv_dir, Config), put(image_size, {W,H}), Im0 = egd_primitives:create(W, H), @@ -159,7 +175,11 @@ image_primitives(Config) when is_list(Config) -> ok = bitmap_point_has_color(Bitmap, {W,H}, Pt2, Fgc), ok = bitmap_point_has_color(Bitmap, {W,H}, Pt1, Fgc), - <<_/binary>> = egd_render:binary(Im2, alpha), + Bin = <<_/binary>> = egd_render:binary(Im2, alpha), + Png = egd_png:binary(W,H,Bin), + File = filename:join(Dir,"image_primitives.png"), + ok = egd:save(Png,File), + ct:log("

Image:

~n", [File]), erase(image_size), ok. @@ -167,6 +187,7 @@ image_primitives(Config) when is_list(Config) -> %% Image font test. image_font(Config) when is_list(Config) -> {W,H} = get_size(proplists:get_value(max_size, Config)), + Dir = proplists:get_value(priv_dir, Config), put(image_size, {W,H}), Im = egd:create(W, H), Fgc = egd:color({0,130,0}), @@ -187,25 +208,46 @@ image_font(Config) when is_list(Config) -> GlyphStr4 = "{|}~", % Codes 123 -> 126 ok = egd:text(Im, get_point(), Font, GlyphStr1, Fgc), - <<_/binary>> = egd:render(Im, png), + Png1 = <<_/binary>> = egd:render(Im, png), + File1 = filename:join(Dir,"text1.png"), + ok = egd:save(Png1,File1), + ct:log("

Image:

~n", [File1]), ok = egd:text(Im, get_point(), Font, NumericStr, Fgc), - <<_/binary>> = egd:render(Im, png), + Png2 = <<_/binary>> = egd:render(Im, png), + File2 = filename:join(Dir,"text2.png"), + ok = egd:save(Png2,File2), + ct:log("

Image:

~n", [File2]), ok = egd:text(Im, get_point(), Font, GlyphStr2, Fgc), - <<_/binary>> = egd:render(Im, png), + Png3 = <<_/binary>> = egd:render(Im, png), + File3 = filename:join(Dir,"text3.png"), + ok = egd:save(Png3,File3), + ct:log("

Image:

~n", [File3]), ok = egd:text(Im, get_point(), Font, AlphaBigStr, Fgc), - <<_/binary>> = egd:render(Im, png), + Png4 = <<_/binary>> = egd:render(Im, png), + File4 = filename:join(Dir,"text4.png"), + ok = egd:save(Png4,File4), + ct:log("

Image:

~n", [File4]), ok = egd:text(Im, get_point(), Font, GlyphStr3, Fgc), - <<_/binary>> = egd:render(Im, png), + Png5 = <<_/binary>> = egd:render(Im, png), + File5 = filename:join(Dir,"text5.png"), + ok = egd:save(Png5,File5), + ct:log("

Image:

~n", [File5]), ok = egd:text(Im, get_point(), Font, AlphaSmStr, Fgc), - <<_/binary>> = egd:render(Im, png), + Png6 = <<_/binary>> = egd:render(Im, png), + File6 = filename:join(Dir,"text6.png"), + ok = egd:save(Png6,File6), + ct:log("

Image:

~n", [File6]), ok = egd:text(Im, get_point(), Font, GlyphStr4, Fgc), - <<_/binary>> = egd:render(Im, png), + Png7 = <<_/binary>> = egd:render(Im, png), + File7 = filename:join(Dir,"text7.png"), + ok = egd:save(Png7,File7), + ct:log("

Image:

~n", [File7]), ok = egd:destroy(Im), erase(image_size), @@ -244,21 +286,36 @@ image_fans(Config) when is_list(Config) -> Bin1 = egd_render:binary(Im1, opaque), Png1 = egd_png:binary(W,H,Bin1), - File1 = filename:join(Dir,"fan1.png"), - egd:save(Png1,File1), - ct:log("

Image1:

~n", [File1]), + File1 = filename:join(Dir,"fan1_opaque.png"), + ok = egd:save(Png1,File1), + ct:log("

Image opaque width 1:

~n", [File1]), + + Bin2 = egd_render:binary(Im1, alpha), + Png2 = egd_png:binary(W,H,Bin2), + + File2 = filename:join(Dir,"fan1_alpha.png"), + ok = egd:save(Png2,File2), + ct:log("

Image alpha width 1:

~n", [File2]), + %% fan2 Ops3 = gen_vertical_fan(7,{0,400},egd:color(red),1024,800,-15), Ops4 = gen_horizontal_fan(7,{512,800},egd:color(green),1024,0,-15), Im2 = lists:foldl(Fun, Im0, Ops3 ++ Ops4), - Bin2 = egd_render:binary(Im2, opaque), - Png2 = egd_png:binary(W,H,Bin2), + Bin3 = egd_render:binary(Im2, opaque), + Png3 = egd_png:binary(W,H,Bin3), + + File3 = filename:join(Dir,"fan2_opaque.png"), + ok = egd:save(Png3,File3), + ct:log("

Image opaque width 7:

~n", [File3]), - File2 = filename:join(Dir,"fan2.png"), - egd:save(Png2,File2), - ct:log("

Image2:

~n", [File2]), + Bin4 = egd_render:binary(Im2, alpha), + Png4 = egd_png:binary(W,H,Bin4), + + File4 = filename:join(Dir,"fan2_alpha.png"), + ok = egd:save(Png4,File4), + ct:log("

Image alpha width 7:

~n", [File4]), ok. gen_vertical_fan(Wd,Pt,C,X,Y,Step) when Y > 0 -> @@ -285,33 +342,6 @@ bitmap_point_has_color(Bitmap, {W,_}, {X,Y}, C) -> {error, {Other,{CR,CG,CB}}} end. -%% jfif header by specification -%% 2 bytes, length -%% 5 bytes, identifier ="JFIF\0" -%% 2 bytes, version, (major, minor) -%% 1 byte , units -%% However, JFIF seems to start at 6 (7 with 1-index)? - -binary_is_jfif_compliant(JpegBin) -> - {Bin, _} = split_binary(JpegBin, 11), - List = binary_to_list(Bin), - case lists:sublist(List, 7, 4) of - "JFIF" -> true; - Other -> - io:format("img -> ~p~n", [Other]), - false - end. - -binary_is_gif_compliant(GifBin) -> - {Bin, _} = split_binary(GifBin, 10), - List = binary_to_list(Bin), - case lists:sublist(List, 1,5) of - "GIF87" -> true; - Other -> - io:format("img -> ~p~n", [Other]), - false - end. - binary_is_png_compliant(PngBin) -> {Bin, _} = split_binary(PngBin, 10), List = binary_to_list(Bin), -- cgit v1.2.3