1//<-- CLI SHELL MODE -->
2//<-- NO CHECK REF -->
3// =============================================================================
4// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
5// Copyright (C) ????-2008 - INRIA
6// Copyright (C) 2009 - DIGITEO - Allan CORNET
7//
8//  This file is distributed under the same license as the Scilab package.
9// =============================================================================
10fptr_cos = funptr("cos");
11newfun("cosAlias",fptr_cos);
12
13assert_checkequal(cos(2*%pi), cosAlias(2*%pi));
14assert_checktrue(clearfun("cosAlias"));
15if execstr("cosAlias(2*%pi)","errcatch") ==  0  then pause,end
16
17errmsg =  msprintf(gettext("%s: Wrong value for input argument #%d: Valid function name expected.\n"), "newfun", 1);
18assert_checkerror('newfun(''1_function_name'',fptr_cos)', errmsg);
19
20errmsg =  msprintf(gettext("%s: Wrong size for input argument #%d: string expected.\n"), "newfun", 2);
21assert_checkerror('newfun(''new_function_name'',[fptr_cos,fptr_cos])', errmsg);
22
23errmsg =  msprintf(gettext("%s: Wrong size for input argument #%d: string expected.\n"), "newfun", 1);
24assert_checkerror('newfun([''new_function_name'',''new_function_name''],[fptr_cos,fptr_cos])', errmsg);
25
26errmsg =  msprintf(gettext("%s: Wrong type for input argument #%d: String expected.\n"), "newfun", 1);
27assert_checkerror('newfun(1,[fptr_cos,fptr_cos])', errmsg);
28
29function test_1(x)
30    newfun(x, "cos");
31    assert_checkequal(evstr(x + "(1)"), cos(1));
32endfunction
33
34test_1("cosAlias");
35assert_checkequal(cosAlias(1), cos(1));
36assert_checktrue(clearfun("cosAlias"));
37
38function test_2(x)
39    test_1(x);
40    assert_checkequal(evstr(x + "(1)"), cos(1));
41endfunction
42
43test_2("cosAlias");
44assert_checkequal(cosAlias(1), cos(1));
45assert_checktrue(clearfun("cosAlias"));
46
47function test_3(x)
48    test_2(x);
49    assert_checkequal(evstr(x + "(1)"), cos(1));
50endfunction
51
52test_3("cosAlias");
53assert_checkequal(cosAlias(1), cos(1));
54assert_checktrue(clearfun("cosAlias"));
55
56
57myvar = 3;
58newfun("myvar", fptr_cos);
59assert_checkequal(myvar, 3);
60clear myvar
61assert_checkequal(myvar(0), cos(0));
62