OLD | NEW |
| (Empty) |
1 // Copyright (c) 2010 The Ginsu Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef C_SALT_INTEGRATION_TESTS_METHOD_TESTER_H_ | |
6 #define C_SALT_INTEGRATION_TESTS_METHOD_TESTER_H_ | |
7 | |
8 #include <string> | |
9 #include <map> | |
10 #include <vector> | |
11 | |
12 #include "c_salt/scriptable_native_object.h" | |
13 #include "c_salt/scripting_bridge_ptrs.h" | |
14 #include "c_salt/scripting_interface.h" | |
15 | |
16 // A class to test calling methods across the ScriptingBridge. | |
17 class MethodTester : public c_salt::ScriptableNativeObject { | |
18 public: | |
19 MethodTester() {} | |
20 virtual ~MethodTester() {} | |
21 | |
22 private: | |
23 // Methods to implement ScriptableNativeObject: | |
24 virtual void InitializeMethods(c_salt::ScriptingBridge* bridge); | |
25 virtual void InitializeProperties(c_salt::ScriptingBridge* bridge); | |
26 | |
27 // Methods to expose to JavaScript: | |
28 | |
29 // Append 2 strings and return the result. | |
30 // Note that the 1st arg is const-ref and the 2nd by-value on purpose, to make | |
31 // sure we exercise both styles of argument passing. | |
32 std::string AppendStrings(const std::string& s1, std::string s2); | |
33 | |
34 // TODO(dmichael): Add support for containers so we can do this | |
35 // std::string AppendStringArray(const std::vector<std::string>& s_vec); | |
36 | |
37 // Add 2 doubles and return the result. | |
38 double AddDoubles(const double& d1, double d2); | |
39 // Add 2 integers and return the result. | |
40 int32_t AddInts(const int32_t& i1, int32_t i2); | |
41 // Return (b1 && b2). | |
42 bool AndBools(const bool& b1, bool b2); | |
43 | |
44 // This one tests the ability to call methods via the ScriptingInterface. | |
45 // |method_name| is the name of a method to invoke, |script_object| is a | |
46 // ScriptingInterface (could be a JavaScript object or a ScriptingBridge) on | |
47 // which we should invoke the method, and |parameter| is a parameter to | |
48 // pass to the method. When the method returns, CallMethodOnScriptObject | |
49 // returns that return value back out. | |
50 c_salt::Variant CallMethodOnScriptObject( | |
51 const std::string& method_name, | |
52 boost::shared_ptr<c_salt::ScriptingInterface> script_object, | |
53 const c_salt::SharedVariant& parameter); | |
54 | |
55 // Call the function that is passed in as |script_object| with |parameter|. | |
56 c_salt::Variant CallAnonymousFunction( | |
57 boost::shared_ptr<c_salt::ScriptingInterface> script_object, | |
58 const c_salt::SharedVariant& parameter); | |
59 }; | |
60 | |
61 #endif // C_SALT_INTEGRATION_TESTS_METHOD_TESTER_H_ | |
OLD | NEW |