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 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103
|
// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
// Copyright (C) DIGITEO - 2010-2010 - Clément DAVID <clement.david@scilab.org>
//
// This file is distributed under the same license as the Scilab package.
// <-- XCOS TEST -->
// <-- ENGLISH IMPOSED -->
//
// <-- Short Description -->
// White-box test for the xcosPalAddBlock macro.
//
// Init
//
iconPath = SCI + "/modules/xcos/images/palettes/NPN.png";
stylePath = SCI + "/modules/xcos/images/blocks/NPN.svg";
scs_m = SUM_f("define");
blockPath = TMPDIR + "/block.sod";
//
// Test block argument
//
// check call with a block name only
pal = xcosPal();
pal = xcosPalAddBlock(pal, "SUM_f");
if getos() == 'Windows' then
root_url = "file:///";
else
root_url = "file://";
end
expectedResult = ["SUM_f" msprintf("%s/SUM_f.gif", TMPDIR) msprintf("noLabel=1;image="+ root_url +"%s/SUM_f.svg;", TMPDIR)];
expectedResult = strsubst(expectedResult, '\', '/');
result = [pal.blockNames(1) pal.icons(1) pal.style(1)];
result = strsubst(result, '\', '/');
if or(expectedResult <> result) then bugmes();quit;end
// check call with a block instance only
pal = xcosPal();
pal = xcosPalAddBlock(pal, scs_m);
expectedResult = ["SUM_f" msprintf("%s/SUM_f.gif", TMPDIR) msprintf("noLabel=1;image="+ root_url +"%s/SUM_f.svg;", TMPDIR)];
expectedResult = strsubst(expectedResult, '\', '/');
result = [pal.blockNames(1) pal.icons(1) pal.style(1)];
result = strsubst(result, '\', '/');
if or(expectedResult <> result) then bugmes();quit;end
// check call with a stored block instance
pal = xcosPal();
export_to_hdf5(blockPath, "scs_m");
pal = xcosPalAddBlock(pal, blockPath);
expectedResult = ["SUM_f" msprintf("%s/SUM_f.gif", TMPDIR) msprintf("noLabel=1;image="+ root_url +"%s/SUM_f.svg;", TMPDIR)];
expectedResult = strsubst(expectedResult, '\', '/');
result = [pal.blockNames(1) pal.icons(1) pal.style(1)];
result = strsubst(result, '\', '/');
if or(expectedResult <> result) then bugmes();quit;end
// check call with empty icon and style
pal = xcosPal();
pal = xcosPalAddBlock(pal, blockPath, [], []);
expectedResult = ["SUM_f" msprintf("%s/SUM_f.gif", TMPDIR) msprintf("noLabel=1;image="+ root_url +"%s/SUM_f.svg;", TMPDIR)];
expectedResult = strsubst(expectedResult, '\', '/');
result = [pal.blockNames(1) pal.icons(1) pal.style(1)];
result = strsubst(result, '\', '/');
if or(expectedResult <> result) then bugmes();quit;end
//
// Test pal_block_img argument
//
// check call with a relative icon path
pal = xcosPal();
pal = xcosPalAddBlock(pal, blockPath, iconPath);
current = pwd();
cd(SCI);
pal = xcosPal();
pal = xcosPalAddBlock(pal, blockPath, "modules/xcos/images/palettes/NPN.png");
expectedResult = ["SUM_f" iconPath msprintf("noLabel=1;image="+ root_url +"%s/SUM_f.svg;", TMPDIR)];
expectedResult = strsubst(expectedResult, '\', '/');
result = [pal.blockNames(1) pal.icons(1) pal.style(1)];
result = strsubst(result, '\', '/');
if or(expectedResult <> result) then bugmes();quit;end
cd(current);
//
// Test style argument
//
// check call with an empty icon and a struct style
myStyle = struct();
myStyle.block = [];
myStyle.image = root_url + iconPath;
pal = xcosPal();
pal = xcosPalAddBlock(pal, blockPath, [], myStyle);
expectedResult = ["SUM_f" msprintf("%s/SUM_f.gif", TMPDIR) msprintf("block;image="+ root_url +"%s;", iconPath)];
expectedResult = strsubst(expectedResult, '\', '/');
result = [pal.blockNames(1) pal.icons(1) pal.style(1)];
result = strsubst(result, '\', '/');
if or(expectedResult <> result) then bugmes();quit;end
// check call with an empty icon and a path style
pal = xcosPal();
pal = xcosPalAddBlock(pal, blockPath, [], iconPath);
expectedResult = ["SUM_f" msprintf("%s/SUM_f.gif", TMPDIR) msprintf("shape=label;image="+ root_url +"%s;", iconPath)];
expectedResult = strsubst(expectedResult, '\', '/');
result = [pal.blockNames(1) pal.icons(1) pal.style(1)];
result = strsubst(result, '\', '/');
if or(expectedResult <> result) then bugmes();quit;end
// check a full call with only paths (eg for toolbox creation)
pal = xcosPal();
pal = xcosPalAddBlock(pal, blockPath, iconPath, stylePath);
expectedResult = ["SUM_f" iconPath msprintf("shape=label;image="+ root_url +"%s;", stylePath)];
expectedResult = strsubst(expectedResult, '\', '/');
result = [pal.blockNames(1) pal.icons(1) pal.style(1)];
result = strsubst(result, '\', '/');
if or(expectedResult <> result) then bugmes();quit;end
|