void DemoApp::Quit() { TTValue out; TTLogMessage("\n*** Release mApplicationDemo datas ***\n"); ///////////////////////////////////////////////////////////////////// // Unregister the parameter if ( mApplicationDemo.send("ObjectUnregister", "/myParameter", out)) TTLogError("Error : can't unregister data at /myParameter address \n"); // Unregister the message if (mApplicationDemo.send("ObjectUnregister", "/myMessage", out)) TTLogError("Error : can't unregister data at /myMessage address \n"); // Unregister the return if (mApplicationDemo.send("ObjectUnregister", "/myReturn", out)) TTLogError("Error : can't unregister data at /myReturn address \n"); TTLogMessage("\n*** Release application ***\n"); ///////////////////////////////////////////////////////////////////// mApplicationManager.send("ApplicationRelease", "demo", out); // delete the polling thread if (mPollingThread) mPollingThread->wait(); delete mPollingThread; }
TTErr DemoAppDataReturnValueCallback(const TTValue& baton, const TTValue& value) { DemoApp* demoApp = (DemoApp*)TTPtr(baton[0]); TTObject anObject = baton[1]; // Reteive which data has been updated if (anObject.instance() == demoApp->mDataDemoParameter.instance()) { // print the returned value TTLogMessage("/myParameter has been updated to %s \n", value.toString().data()); return kTTErrNone; } if (anObject.instance() == demoApp->mDataDemoMessage.instance()) { // print the returned value TTLogMessage("/myMessage has been updated to %s \n", value.toString().data()); return kTTErrNone; } if (anObject.instance() == demoApp->mDataDemoReturn.instance()) { // print the returned value TTLogMessage("/myReturn has been updated to %s \n", value.toString().data()); return kTTErrNone; } return kTTErrGeneric; }
void TTScoreInitialize() { // Initialized Foundation framework TTFoundationInit(); if (!TTScoreInitialized) { TTScoreInitialized = true; // register classes -- both internal and external TTTimeCondition::registerClass(); TTTimeContainer::registerClass(); TTTimeEvent::registerClass(); TTTimeProcess::registerClass(); TTScoreTest::registerClass(); #ifdef TT_DEBUG TTLogMessage("Score -- Version %s -- Debugging Enabled\n", TTSCORE_VERSION_STRING); #else TTLogMessage("Score -- Version %s\n", TTSCORE_VERSION_STRING); #endif } }
int main(int argc, char **argv) { DemoApp app; TTLogMessage("\n*** Start of Jamoma Modular and Score demonstration ***\n"); app.SetupModular(); app.SetupScore(); // read command from console do { TTLogMessage("\nType a command : \n"); std::string s; std::getline(std::cin, s); // quit the application if (!s.compare("quit")) { app.Quit(); TTLogMessage("\n*** End of Jamoma Modular and Score demonstration ***\n"); return EXIT_SUCCESS; } // update mDataDemoMessage data with the command else { app.SetMessage(s); } } while (YES); }
void TTFoundationInit() { if (!TTFoundationHasInitialized) { TTFoundationHasInitialized = true; ttSymbolTable = new TTSymbolTable; for (int i=0; i<kNumTTDataTypes; i++) TTDataInfo::addDataInfoForType(TTDataType(i)); ttEnvironment = new TTEnvironment; TTSymbolCacheInit(); TTValueCacheInit(); #ifdef TT_DEBUG TTLogMessage("JamomaFoundation -- Version %s -- Debugging Enabled\n", TTFOUNDATION_VERSION_STRING); #else TTLogMessage("JamomaFoundation -- Version %s\n", TTFOUNDATION_VERSION_STRING); #endif // register classes -- both internal and external TTCallback::registerClass(); TTNode::registerClass(); TTNodeDirectory::registerClass(); TTFoundationLoadExternalClasses(); } }
void DemoApp::SetupScore() { TTValue args, out; TTObject xmlHandler("XmlHandler"); TTLogMessage("\n*** Initialisation of Score environnement ***\n"); ///////////////////////////////////////////////////////////////////// // Init the Score library (passing the folder path where all the dylibs are) TTScoreInit("/usr/local/jamoma"); TTLogMessage("\n*** Reading of an interactive scenario file ***\n"); ///////////////////////////////////////////////////////////////////// // Create an empty Scenario mScenario = TTObject("Scenario"); // Read DemoScenario1.score file to fill mScenario xmlHandler.set("object", mScenario); xmlHandler.send("Read", "../DemoScenario.score", out); TTLogMessage("\n*** Prepare scenario observation ***\n"); ///////////////////////////////////////////////////////////////////// // Create a callback for the "EventStatusChanged" notification sent by each event mEventStatusChangedCallback = TTObject("callback"); mEventStatusChangedCallback.set("baton", TTPtr(this)); mEventStatusChangedCallback.set("function", TTPtr(&DemoAppEventStatusChangedCallback)); mEventStatusChangedCallback.set("notification", TTSymbol("EventStatusChanged")); // Get all events of the scenario and attach a callback to them TTValue timeEvents; mScenario.get("timeEvents", timeEvents); for (TTElementIter it = timeEvents.begin() ; it != timeEvents.end() ; it++) { TTObject event = TTElement(*it); event.registerObserverForNotifications(mEventStatusChangedCallback); } TTLogMessage("\n*** Start scenario execution ***\n"); ///////////////////////////////////////////////////////////////////// // Set the execution speed of the scenario mScenario.set("speed", 2.); // Start the scenario mScenario.send("Start"); // Poll Scenario information mPollingThread = new TTThread(TTThreadCallbackType(DemoAppScenarioPollingThread), this); }
void TTFoundationInit(const char* pathToBinaries, bool loadFromOtherPaths) { if (!TTFoundationHasInitialized) { TTFoundationHasInitialized = true; if (pathToBinaries) TTFoundationBinaryPath = pathToBinaries; for (int i=0; i<kNumTTDataTypes; i++) TTDataInfo::addDataInfoForType(TTDataType(i)); // Regex requires Boost libraries, not available for iOS for the time-being #ifndef DISABLE_NODELIB TTNodeLibInit(); #endif ttEnvironment = new TTEnvironment; // Regex requires Boost libraries, not available for iOS for the time-being //#ifndef DISABLE_NODELIB // TTAddressCacheInit(); //#endif #ifdef TT_DEBUG TTLogMessage("JamomaFoundation (TT_DEBUG) -- Version %s - %s", JAMOMACORE_VERSION, JAMOMACORE_REV); ttEnvironment->mDebugBasic = true; #else TTLogMessage("JamomaFoundation -- Version %s - %s", JAMOMACORE_VERSION, JAMOMACORE_REV); #endif if (pathToBinaries) TTLogMessage("-- Path %s\n", pathToBinaries); else TTLogMessage("\n"); // register classes -- both internal and external TTCallback::registerClass(); TTMatrixBase::registerClass(); TTMatrixArray::registerClass(); TTObjectTest::registerClass(); TTRegexTest::registerClass(); TTStringTest::registerClass(); TTSymbolTest::registerClass(); TTValueTest::registerClass(); TTInterpolateTest::registerClass(); TTDictionaryTest::registerClass(); TTListTest::registerClass(); // Regex requires Boost libraries, not available for iOS for the time-being #ifndef DISABLE_NODELIB TTNodeLibTest::registerClass(); #endif TTLoadExtensions(pathToBinaries, loadFromOtherPaths); } }
int main(int argc, const char * argv[]) { std::cout << "BEGIN testing for AnalysisLib...\n"; // CUSTOMIZE TTLoadJamomaExtension_AnalysisLib(); // CUSTOMIZE TTValue classNames; // if the follow group tag is present within the thisTTClassTags definition, the class will be tested TTValue testClassesWithTheseTags(TT("dspAnalysisLib")); // CUSTOMIZE TTObject::GetRegisteredClassNamesForTags(classNames, testClassesWithTheseTags); for (int i=0; i<classNames.size(); i++) { TTSymbol name = classNames[i]; try { TTObject obj(name); std::cout << "TESTING " << name.string() << std::endl; obj.send("test"); } catch (...) { TTLogMessage("UnitTest Failure to instantiate object of class %s! \n", name.c_str()); continue; } } std::cout << "END testing of AnalysisLib!\n"; // CUSTOMIZE return 0; }
void TTGraphicsInit() { if(!TTGraphicsHasInitialized){ TTGraphicsHasInitialized = true; TTFoundationInit(); TTGraphicsWindow::registerClass(); TTGraphicsContext::registerClass(); TTGraphicsSurface::registerClass(); #ifdef TT_DEBUG TTLogMessage("JamomaGraphics -- Version %s -- Debugging Enabled\n", TTGRAPHICS_VERSION_STRING); #else TTLogMessage("JamomaGraphics -- Version %s\n", TTGRAPHICS_VERSION_STRING); #endif } }
void TTDSPInit(const char* pathToBinaries) { TTFoundationInit(pathToBinaries); if (!TTDSPHasInitialized) { TTDSPHasInitialized = true; // TODO: someday implement these so that we have project-scoped caches and don't stuff everything into the foundation? //TTDSPSymbolCacheInit(); //TTDSPValueCacheInit(); #ifdef TT_DEBUG TTLogMessage("JamomaDSP -- Version %s -- Debugging Enabled\n", TTDSP_VERSION_STRING); #else TTLogMessage("JamomaDSP -- Version %s\n", TTDSP_VERSION_STRING); #endif TTDSPRegisterInternalClasses(); } }
void TTTestLog(const char *fmtstring, ...) { char str[4096]; char fullstr[4096]; va_list ap; va_start(ap, fmtstring); vsnprintf(str, 4000, fmtstring, ap); va_end(ap); str[4095] = 0; strncpy(fullstr, " ", 4095); strncat(fullstr, str, 4095); strncat(fullstr, "\n", 4095); TTLogMessage(fullstr); }
/** Log messages scoped to this object instance. */ TTErr TTObjectBase::logMessage(TTImmutableCString fmtstring, ...) { char str[4096]; char fullstr[4096]; va_list ap; va_start(ap, fmtstring); vsnprintf(str, 4000, fmtstring, ap); va_end(ap); str[4095] = 0; strncpy(fullstr, classPtr->name.c_str(), 4095); strncat(fullstr, " : ", 4095); strncat(fullstr, str, 4095); TTLogMessage(fullstr); return kTTErrNone; }
TTErr DemoAppEventStatusChangedCallback(const TTValue& baton, const TTValue& value) { DemoApp* demoApp = (DemoApp*)TTPtr(baton[0]); TTObject event = value[0]; TTSymbol newStatus = value[1]; TTSymbol oldStatus = value[2]; // get the name of the event TTSymbol name; event.get("name", name); // print the event status TTLogMessage("%s status : %s \n", name.c_str(), newStatus.c_str()); return kTTErrNone; }
TTBoolean TTTestFloatEquivalence(TTFloat64 aFloat, TTFloat64 bFloat, TTBoolean expectedResult, TTFloat64 epsilon) { if (epsilon <= 0.) { TTLogMessage(" TTTestFloatEquivalence: epsilon must be a positive number\n"); return false; } TTBoolean result; if ((aFloat == kTTTestFloat64Infinity)||(bFloat == kTTTestFloat64Infinity)) { if (aFloat==bFloat) result = true; else result = false; } else { TTFloat64 aAbs = fabs(aFloat); TTFloat64 bAbs = fabs(bFloat); TTFloat64 absoluteOrRelative = (1.0f > aAbs ? 1.0f : aAbs); absoluteOrRelative = (absoluteOrRelative > bAbs ? absoluteOrRelative : bAbs); if (fabs(aFloat - bFloat) <= epsilon * absoluteOrRelative) result = true; else result = false; } // Was this the expected result? if (result == expectedResult) return true; else { #ifdef NOISY_FAILURE TTLogMessage("\n"); TTLogMessage(" TTTestFloatEquivalence: Unexpected result\n"); TTLogMessage("\n"); TTLogMessage(" aFloat = %.15e\n", aFloat); TTLogMessage(" bFloat = %.15e\n", bFloat); TTLogMessage(" result = %s\n", (result)?"true":"false"); TTLogMessage("\n"); #endif return false; } }
NSPStatus Namespace::namespaceDisplay(void) { unsigned int i; TTValue hk; TTSymbolPtr key; if (NSPDirectory) { NSPDirectory->getDirectory()->getKeys(hk); for (i = 0; i < NSPDirectory->getDirectory()->getSize(); i++) { hk.get(i,(TTSymbol**)&key); TTLogMessage("%s\n",key->getCString()); } return NSP_NO_ERROR; } //TTLogMessage("NSPDirectory_dump : create a directory before"); return NSP_INIT_ERROR; }
TTErr SpeedDataspace::test(TTValue& returnedTestInfo) { int errorCount = 0; int testAssertionCount = 0; // Create dataspace object and set to temperature try { TTObject myDataspace("dataspace"); myDataspace.set(TT("dataspace"), TT("speed")); TTValue v; TTValue expected; /************************************************/ /* */ /* Test conversions to neutral unit */ /* */ /************************************************/ // meterPerSecond => meterPerSecond myDataspace.set(TT("inputUnit"), TT("m/s")); myDataspace.set(TT("outputUnit"), TT("m/s")); v = TTValue(256.); expected = TTValue(256.); myDataspace.send(TT("convert"), v, v); TTTestAssertion("m/s to m/s", TTTestFloatEquivalence(TTFloat64(v), TTFloat64(expected)), testAssertionCount, errorCount); // kilometerPerHour => meterPerSecond // Trivial conversion: 36 km/h = (36000 m) / (60*60 s) = 10 m/s myDataspace.set(TT("inputUnit"), TT("kmph")); myDataspace.set(TT("outputUnit"), TT("m/s")); v = TTValue(36.); expected = TTValue(10.0); myDataspace.send(TT("convert"), v, v); TTTestAssertion("kmph to m/s", TTTestFloatEquivalence(TTFloat64(v), TTFloat64(expected)), testAssertionCount, errorCount); // milesPerHour => meterPerSecond // Expected value according to Google search: "50 miles per hour to m/s" myDataspace.set(TT("inputUnit"), TT("mph")); myDataspace.set(TT("outputUnit"), TT("m/s")); v = TTValue(50.); expected = TTValue(22.35200); myDataspace.send(TT("convert"), v, v); TTTestAssertion("miles per hour to m/s", TTTestFloatEquivalence(TTFloat64(v), TTFloat64(expected)), testAssertionCount, errorCount); // knot => meterPerSecond // Expected value according to Google search: "45 knot to m/s" // This is a somewhat rough estimate, with limited precision myDataspace.set(TT("inputUnit"), TT("kn")); myDataspace.set(TT("outputUnit"), TT("m/s")); v = TTValue(45.); expected = TTValue(23.15); myDataspace.send(TT("convert"), v, v); TTTestAssertion("knot to m/s", TTTestFloatEquivalence(TTFloat64(v), TTFloat64(expected), true, 0.1), testAssertionCount, errorCount); // footPerSecond => meterPerSecond // Expected value according to Google search: "20 foot per second to m/s" myDataspace.set(TT("inputUnit"), TT("ft/s")); myDataspace.set(TT("outputUnit"), TT("m/s")); v = TTValue(20.); expected = TTValue(6.09600); myDataspace.send(TT("convert"), v, v); TTTestAssertion("foot per hour to m/s", TTTestFloatEquivalence(TTFloat64(v), TTFloat64(expected)), testAssertionCount, errorCount); /************************************************/ /* */ /* Test conversions from neutral unit */ /* */ /************************************************/ // meterPerSecond =>kilometerPerHour myDataspace.set(TT("inputUnit"), TT("m/s")); myDataspace.set(TT("outputUnit"), TT("kmph")); v = TTValue(10.); expected = TTValue(36.0); myDataspace.send(TT("convert"), v, v); TTTestAssertion("m/s to kmph", TTTestFloatEquivalence(TTFloat64(v), TTFloat64(expected)), testAssertionCount, errorCount); // milesPerHour => meterPerSecond // Expected value according to Google search: "50 miles per hour to m/s" myDataspace.set(TT("inputUnit"), TT("m/s")); myDataspace.set(TT("outputUnit"), TT("mph")); v = TTValue(22.35200); expected = TTValue(50.); myDataspace.send(TT("convert"), v, v); TTTestAssertion("m/s to miles per hour", TTTestFloatEquivalence(TTFloat64(v), TTFloat64(expected), true, 0.00001), testAssertionCount, errorCount); // knot => meterPerSecond // Expected value according to Google search: "45 knot to m/s" // This is a somewhat rough estimate, with limited precision myDataspace.set(TT("inputUnit"), TT("m/s")); myDataspace.set(TT("outputUnit"), TT("kn")); v = TTValue(23.15); expected = TTValue(45.); myDataspace.send(TT("convert"), v, v); TTTestAssertion("m/s to knot", TTTestFloatEquivalence(TTFloat64(v), TTFloat64(expected), true, 0.1), testAssertionCount, errorCount); // footPerSecond => meterPerSecond // Expected value according to Google search: "20 foot per second to m/s" myDataspace.set(TT("inputUnit"), TT("m/s")); myDataspace.set(TT("outputUnit"), TT("ft/s")); v = TTValue(6.09600); expected = TTValue(20.); myDataspace.send(TT("convert"), v, v); TTTestAssertion("m/s to foot per hour", TTTestFloatEquivalence(TTFloat64(v), TTFloat64(expected), true, 0.00001), testAssertionCount, errorCount); } catch (...) { TTLogMessage("SpeedDataspace::test TOTAL FAILURE"); errorCount = 1; testAssertionCount = 1; } return TTTestFinish(testAssertionCount, errorCount, returnedTestInfo); }
void TTFoundationLoadExternalClassesFromFolder(const TTString& fullpath) { #ifdef TT_PLATFORM_MAC FSRef ref; Boolean isDirectory; OSStatus status = noErr; ItemCount count = 0; FSIterator iterator; HFSUniStr255* names = NULL; CFStringRef name; char cname[4096]; TTString path; TTCString cpath = (char*)fullpath.c_str(); void* handle; TTExtensionInitializationMethod initializer; TTErr err; status = FSPathMakeRef((UInt8*)cpath, &ref, &isDirectory); if (status != noErr) { #ifdef TT_DEBUG TTLogMessage("TTFoundation - no extensions location found @ %s\n", cpath); #endif return; } status = FSOpenIterator(&ref, kFSIterateFlat, &iterator); if (!status) { names = (HFSUniStr255 *)malloc(sizeof(HFSUniStr255) * 4096); if (names) { // Request information about files in the given directory, // until we get a status code back from the File Manager do{ status = FSGetCatalogInfoBulk(iterator, 4096, &count, NULL, kFSCatInfoNone, NULL, NULL, NULL, names); // Process all items received if (status == OSStatus(noErr) || status == OSStatus(errFSNoMoreItems)) { for (UInt32 i=0; i < count; i += 1) { name = CFStringCreateWithCharacters(kCFAllocatorDefault, names[i].unicode, names[i].length); // TODO: filter on name. We only want to try and load .ttdylib files CFStringGetCString(name, cname, 4096, kCFStringEncodingUTF8); path = fullpath; path += "/"; path += cname; handle = dlopen(path.c_str(), RTLD_LAZY); // TODO: assert -- or at least do a log post -- if handle is NULL initializer = (TTExtensionInitializationMethod)dlsym(handle, "loadTTExtension"); if (initializer) err = initializer(); CFRelease(name); } } } while (status == OSStatus(noErr)); // errFSNoMoreItems tells us we have successfully processed all // items in the directory -- not really an error if (status == OSStatus(errFSNoMoreItems)) status = noErr; // Free the array memory free( (void *) names ); } FSCloseIterator(iterator); } #elif TT_PLATFORM_WIN HANDLE fdHandle; WIN32_FIND_DATA findFileData; TTString path; HANDLE hLib = NULL; TTExtensionInitializationMethod initializer; TTErr err; path = fullpath; path += "*.ttdll"; fdHandle = FindFirstFile(path.c_str(), &findFileData); if (fdHandle && (fdHandle != INVALID_HANDLE_VALUE)) { while (fdHandle) { path = fullpath; path += findFileData.cFileName; hLib = LoadLibrary(path.c_str()); if (hLib) { initializer = (TTExtensionInitializationMethod)GetProcAddress((HMODULE)hLib, "loadTTExtension"); if (initializer) err = initializer(); } if (!FindNextFile(fdHandle, &findFileData)) break; } } #else ; #endif }
void DemoApp::SetupModular() { TTValue args, v, out, none; TTAddress address; TTErr err; TTLogMessage("\n*** Initialisation of Modular environnement ***\n"); ///////////////////////////////////////////////////////////////////// // Init the Modular library (passing the folder path where all the dylibs are) TTModularInit("/usr/local/jamoma"); // Create an application manager mApplicationManager = TTObject("ApplicationManager"); TTLogMessage("\n*** Creation of mApplicationDemo application ***\n"); ///////////////////////////////////////////////////////////////////// // Create a local application called "demo" and get it back err = mApplicationManager.send("ApplicationInstantiateLocal", "demo", out); if (err) { TTLogError("Error : can't create demo application \n"); return; } else mApplicationDemo = out[0]; TTLogMessage("\n*** Creation of mApplicationDemo datas ***\n"); ///////////////////////////////////////////////////////////////////// // Create a parameter data and set its callback function and baton and some attributes mDataDemoParameter = TTObject("Data", "parameter"); // Setup the callback mechanism to get the value back args = TTValue(TTPtr(this), mDataDemoParameter); mDataDemoParameter.set("baton", args); mDataDemoParameter.set("function", TTPtr(&DemoAppDataReturnValueCallback)); // Setup the data attributes depending of its use inside the application mDataDemoParameter.set("type", "decimal"); mDataDemoParameter.set("rangeBounds", TTValue(0., 1.)); mDataDemoParameter.set("rangeClipmode", "low"); mDataDemoParameter.set("description", "any information relative to the state of the application"); // Register the parameter data into mApplicationDemo at an address args = TTValue("/myParameter", mDataDemoParameter); mApplicationDemo.send("ObjectRegister", args, out); // Create a message data and set its callback function and baton and some attributes mDataDemoMessage = TTObject("Data", "message"); // Setup the callback mechanism to get the value back args = TTValue(TTPtr(this), mDataDemoMessage); mDataDemoMessage.set("baton", args); mDataDemoMessage.set("function", TTPtr(&DemoAppDataReturnValueCallback)); // Setup the data attributes depending of its use inside the application mDataDemoMessage.set("type", "string"); mDataDemoMessage.set("description", "any information to provide to the application"); // Register the message data into mApplicationDemo at an address args = TTValue("/myMessage", mDataDemoMessage); mApplicationDemo.send("ObjectRegister", args, out); // Create a return data and set its callback function and baton and some attributes mDataDemoReturn = TTObject("Data", "return"); // Setup the callback mechanism to get the value back args = TTValue(TTPtr(this), mDataDemoReturn); mDataDemoReturn.set("baton", args); mDataDemoReturn.set("function", TTPtr(&DemoAppDataReturnValueCallback)); // Setup the data attributes depending of its use inside the application mDataDemoReturn.set("type", "integer"); mDataDemoReturn.set("defaultValue", 0); mDataDemoReturn.set("description", "any information the application returns back"); // Register the return data into mApplicationDemo at an address args = TTValue("/myReturn", mDataDemoReturn); mApplicationDemo.send("ObjectRegister", args, out); // Initialise the application and all datas inside (using defaultValue attribute) mApplicationDemo.send("Init"); }
TTErr TemperatureDataspace::test(TTValue& returnedTestInfo) { int errorCount = 0; int testAssertionCount = 0; // Create dataspace object and set to temperature try { TTObject myDataspace("dataspace"); myDataspace.set(TT("dataspace"), TT("temperature")); TTValue v; TTValue expected; /************************************************/ /* */ /* Test conversions to neutral unit */ /* */ /************************************************/ // Kelvin => Kelvin myDataspace.set(TT("inputUnit"), TT("Kelvin")); myDataspace.set(TT("outputUnit"), TT("Kelvin")); v = TTValue(256.); expected = TTValue(256.); myDataspace.send(TT("convert"), v, v); TTTestAssertion("Kelvin to Kelvin", TTTestFloatEquivalence(TTFloat64(v), TTFloat64(expected)), testAssertionCount, errorCount); // Celsius => Kelvin // Expected value according to Google search: "0 Celsius to Kelvin" myDataspace.set(TT("inputUnit"), TT("Celsius")); myDataspace.set(TT("outputUnit"), TT("Kelvin")); v = TTValue(0.); expected = TTValue(273.15); myDataspace.send(TT("convert"), v, v); TTTestAssertion("Celsius to Kelvin", TTTestFloatEquivalence(TTFloat64(v), TTFloat64(expected)), testAssertionCount, errorCount); // Fahrenheit => Kelvin // Expected value according to Google search: "32 Farhenheit to Kelvin" myDataspace.set(TT("inputUnit"), TT("Fahrenheit")); myDataspace.set(TT("outputUnit"), TT("Kelvin")); v = TTValue(32.); expected = TTValue(273.15); myDataspace.send(TT("convert"), v, v); TTTestAssertion("Fahrenheit to Kelvin", TTTestFloatEquivalence(TTFloat64(v), TTFloat64(expected)), testAssertionCount, errorCount); /************************************************/ /* */ /* Test conversions from neutral unit */ /* */ /************************************************/ // Kelvin => Celsius // Expected value according to Google search: "0 Celsius to Kelvin" myDataspace.set(TT("inputUnit"), TT("Kelvin")); myDataspace.set(TT("outputUnit"), TT("Celsius")); v = TTValue(273.15); expected = TTValue(0.0); myDataspace.send(TT("convert"), v, v); TTTestAssertion("Kelvin to Celsius", TTTestFloatEquivalence(TTFloat64(v), TTFloat64(expected)), testAssertionCount, errorCount); // Fahrenheit => Kelvin // Expected value according to Google search: "32 Farhenheit to Kelvin" myDataspace.set(TT("inputUnit"), TT("Kelvin")); myDataspace.set(TT("outputUnit"), TT("Fahrenheit")); v = TTValue(273.15); expected = TTValue(32.0); myDataspace.send(TT("convert"), v, v); TTTestAssertion("Kelvin to Fahrenheit", TTTestFloatEquivalence(TTFloat64(v), TTFloat64(expected)), testAssertionCount, errorCount); } catch (...) { TTLogMessage("TemperatureDataspace::test TOTAL FAILURE"); errorCount = 1; testAssertionCount = 1; } return TTTestFinish(testAssertionCount, errorCount, returnedTestInfo); }