Page Menu
Home
Xreate
Search
Configure Global Search
Log In
Docs
Questions
Repository
Issues
Patches
Internal API
Files
F4000291
unit-test-example.cpp
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Thu, Jul 9, 3:56 AM
Size
987 B
Mime Type
text/x-c++
Expires
Sat, Jul 11, 3:56 AM (1 d, 5 h)
Engine
blob
Format
Raw Data
Handle
273270
Attached To
rXR Xreate
unit-test-example.cpp
View Options
#include "xreatemanager.h" //main Xreate header
#include "transcendlayer.h"
#include <gtest/gtest.h>
using namespace xreate;
using namespace std;
TEST(Example, Example1){
//Your custom transcend rules if any
string rules =
R"SCRIPT(
bind_func(sum, entry).
)SCRIPT";
//Your custom program
string example =
R"CODE(
//Custom code
sum = function(a:: int, b:: int):: int
{
a + b
}
)CODE";
//Initialize compiler
unique_ptr<XreateManager> man(XreateManager::prepare(move(example)));
//Add transcend part:
man->transcend->addRawScript(move(rules));
//Define signature of your entry function:
typedef int (*ENTRYFN)(int, int);
//Compile the example and get a pointer to the entry function:
ENTRYFN yourEntryFn = (ENTRYFN) man->run();
//Now execute function and check the result
int resultActual = yourEntryFn(5, 7);
int resultExpected = 5 + 7;
ASSERT_EQ(resultExpected, resultActual);
}
Event Timeline
Log In to Comment