void cue_edit(TTPtr self, t_symbol *msg, long argc, const t_atom *argv) { WrappedModularInstancePtr x = (WrappedModularInstancePtr)self; TTString *buffer; char title[MAX_FILENAME_CHARS]; TTObject aTextHandler; TTHashPtr allCues; TTValue v, o; TTSymbol name = kTTSymEmpty; t_atom a; TTErr tterr; // choose object to edit : default the cuelist *EXTRA->toEdit = x->wrappedObject; EXTRA->cueName = kTTSymEmpty; if (argc && argv) { if (atom_gettype(argv) == A_LONG) { TTUInt32 index = atom_getlong(argv); // get cues names x->wrappedObject.get("names", v); if (index > 0 && index <= v.size()) name = v[index-1]; else { object_error((t_object*)x, "%d doesn't exist", atom_getlong(argv)); return; } } else if (atom_gettype(argv) == A_SYM) name = TTSymbol(atom_getsym(argv)->s_name); if (name != kTTSymEmpty) { // get cue object table x->wrappedObject.get("cues", v); allCues = TTHashPtr((TTPtr)v[0]); if (allCues) { // get cue to edit if (!allCues->lookup(name, v)) { // edit a cue *EXTRA->toEdit = v[0]; EXTRA->cueName = name; } else { object_error((t_object*)x, "%s doesn't exist", atom_getsym(argv)->s_name); return; } } } } // only one editor can be open in the same time if (!EXTRA->textEditor) { EXTRA->textEditor = (t_object*)object_new(_sym_nobox, _sym_jed, x, 0); buffer = new TTString(); // get the buffer handler tterr = x->internals->lookup(kTTSym_TextHandler, o); if (!tterr) { aTextHandler = o[0]; critical_enter(0); aTextHandler.set(kTTSym_object, *EXTRA->toEdit); tterr = aTextHandler.send(kTTSym_Write, (TTPtr)buffer); critical_exit(0); } // pass the buffer to the editor object_method(EXTRA->textEditor, _sym_settext, buffer->c_str(), _sym_utf_8); object_attr_setchar(EXTRA->textEditor, gensym("scratch"), 1); snprintf(title, MAX_FILENAME_CHARS, "cuelist editor"); object_attr_setsym(EXTRA->textEditor, _sym_title, gensym(title)); // output a flag atom_setsym(&a, gensym("opened")); object_obex_dumpout(self, gensym("editor"), 1, &a); buffer->clear(); delete buffer; buffer = NULL; } else { object_attr_setchar(EXTRA->textEditor, gensym("visible"), 1); } }
void TTStringTestBasic(int& errorCount, int&testAssertionCount) { // TEST: empty string init TTTestLog("\n"); TTTestLog("Testing empty string assigment"); TTString empty; TTTestAssertion("created static const char* arg with correct size", empty.size() == 0, testAssertionCount, errorCount); TTTestAssertion("created from static const char* arg with correct length", empty.length() == 0, testAssertionCount, errorCount); TTTestAssertion("created from static const char* arg correctly null terminated", empty.at(0) == 0, testAssertionCount, errorCount); // TEST: c-string init TTTestLog("\n"); TTTestLog("Testing basic string assigment"); TTString foo("foo"); TTTestAssertion("created from static const char* arg with correct size", foo.size() == 3, testAssertionCount, errorCount); TTTestAssertion("created from static const char* arg with correct length", foo.length() == 3, testAssertionCount, errorCount); TTTestAssertion("created from static const char* arg with correct chars", foo.at(0) == 'f' && foo.at(1) == 'o' && foo.at(2) == 'o', testAssertionCount, errorCount); TTTestAssertion("created from static const char* arg correctly null terminated", foo.at(3) == 0, testAssertionCount, errorCount); // TEST: = init TTTestLog("\n"); TTTestLog("Testing = assigment"); TTString jet; jet = "jet"; TTTestAssertion("created from = with correct size", jet.size() == 3, testAssertionCount, errorCount); TTTestAssertion("created from = with correct length", jet.length() == 3, testAssertionCount, errorCount); TTTestAssertion("created from = with correct chars", jet.at(0) == 'j' && jet.at(1) == 'e' && jet.at(2) == 't', testAssertionCount, errorCount); TTTestAssertion("created from = correctly null terminated", jet.at(3) == 0, testAssertionCount, errorCount); // TEST: clear TTTestLog("\n"); TTTestLog("Testing clear method"); TTString nothing = "something"; nothing.clear(); TTTestAssertion("cleared string with correct size", empty.size() == 0, testAssertionCount, errorCount); TTTestAssertion("cleared string with correct length", empty.length() == 0, testAssertionCount, errorCount); TTTestAssertion("cleared string correctly null terminated", empty.at(0) == 0, testAssertionCount, errorCount); // TEST: individual char access TTTestLog("\n"); TTTestLog("Testing [] assigment"); foo[0] = 'g'; foo[2] = foo[2] + 1; TTTestAssertion("modified some chars using [] notation", foo.at(0) == 'g' && foo.at(1) == 'o' && foo.at(2) == 'p', testAssertionCount, errorCount); // TEST: comparison (depends on the result from above) TTTestLog("\n"); TTTestLog("Testing == operator"); TTString gop("gop"); TTString bar("bar"); TTString foobar("foobar"); TTTestAssertion("== operator when strings have the same content", foo == gop, testAssertionCount, errorCount); TTTestAssertion("== operator when strings have different content", !(foo == bar), testAssertionCount, errorCount); TTTestAssertion("!= operator when strings have the same content", !(foo != gop), testAssertionCount, errorCount); TTTestAssertion("!= operator when strings have different content", (foo != bar), testAssertionCount, errorCount); TTTestAssertion("== operator with c-string when strings have the same content", foo == "gop", testAssertionCount, errorCount); TTTestAssertion("== operator with c-string when strings have different content", !(foo == "bar"), testAssertionCount, errorCount); TTTestAssertion("!= operator with c-string when strings have the same content", !(foo != "gop"), testAssertionCount, errorCount); TTTestAssertion("!= operator with c-string when strings have different content", (foo != "bar"), testAssertionCount, errorCount); // here the length given to the substring is too long // so the foobar string is bar\00 after the substring // bu the last zero makes foobar different to bar foobar = foobar.substr(3, 4); TTTestAssertion("== operator with string when strings have the same content but one created using substr with an oversize length", bar == foobar, testAssertionCount, errorCount); }