⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 test.cpp

📁 LINUX下的混音软件
💻 CPP
📖 第 1 页 / 共 2 页
字号:
// -*- c-basic-offset: 4 -*-// -*- c-file-style:  "bsd" -*-#define NDEBUG// This does some rather shoddy tests on a small selection of core classes.#include "Event.h"#include "Segment.h"#include "Composition.h"//#include "Sets.h"#define TEST_NOTATION_TYPES 1#define TEST_SPEED 1#ifdef TEST_NOTATION_TYPES#include "NotationTypes.h"#include "SegmentNotationHelper.h"#include "SegmentPerformanceHelper.h"#endif#include "MidiTypes.h"#include <cstdio>#include <sys/times.h>#include <iostream>using namespace std;using namespace Rosegarden;static const PropertyName DURATION_PROPERTY = "duration";static const PropertyName SOME_INT_PROPERTY = "someIntProp";static const PropertyName SOME_BOOL_PROPERTY = "someBoolProp";static const PropertyName SOME_STRING_PROPERTY = "someStringProp";static const PropertyName NONEXISTENT_PROPERTY = "nonexistentprop";static const PropertyName ANNOTATION_PROPERTY = "annotation";#if 0// Some attempts at reproducing the func-template-within-template problem// enum FooType {A, B, C};class Foo{public:    template<FooType T> void func();};template<class T>void Foo::func(){    // dummy code    T j = 0;    for(T i = 0; i < 100; ++i) j += i;}//template void Foo::func<int>();template <class R>class FooR{public:    void rfunc();};template<class R>void FooR<R>::rfunc(){    // this won't compile    Foo* foo;    foo->func<A>();}void templateTest(){    Foo foo;    foo.func<A>();//     FooR<float> foor;//     foor.rfunc();}template <class Element, class Container>class GenericSet // abstract base{public:    typedef typename Container::iterator Iterator;    /// Return true if this element, known to test() true, is a set member    virtual bool sample(const Iterator &i);};template <class Element, class Container>boolGenericSet<Element, Container>::sample(const Iterator &i){    Event *e;    long p = e->get<Int>("blah");}#endifint main(int argc, char **argv){    typedef std::vector<int> intvect;    //     intvect foo;//     GenericSet<int, intvect> genset;//     genset.sample(foo.begin());        clock_t st, et;        struct tms spare;#ifdef TEST_WIDE_STRING	basic_string<wchar_t> widestring(L"This is a test");	widestring += L" of wide character strings";	for (unsigned int i = 0; i < widestring.length(); ++i) {	    if (widestring[i] == L'w' ||		widestring[i] == L'c') {		widestring[i] = toupper(widestring[i]);	    }	}	cout << "Testing wide string: string value is \"" << widestring << "\""	     << endl;	cout << "String's length is " << widestring.length() << endl;	cout << "and storage space is " 	     << (widestring.length() * sizeof(widestring[0]))	     << endl;	cout << "Characters are: ";	for (unsigned int i = 0; i < widestring.length(); ++i) {	    cout << widestring[i];	    if (i < widestring.length()-1) cout << " ";	    else cout << endl;	}#endif        cout << "\nTesting Event..." << endl             << "sizeof Event : " << sizeof(Event) << endl;        Event e("note", 0);        e.set<Int>(DURATION_PROPERTY, 20);        cout << "duration is " << e.get<Int>(DURATION_PROPERTY) << endl;        e.set<Bool>(SOME_BOOL_PROPERTY, true);        e.set<String>(SOME_STRING_PROPERTY, "foobar");        cout << "sizeof event after some properties set : "             << sizeof e << endl;        try {                cout << "duration is " << e.get<String>(DURATION_PROPERTY) << endl;        } catch (Event::BadType bt) {                cout << "Correctly caught BadType when trying to get<String> of duration" << endl;        }        string s;            if (!e.get<String>(DURATION_PROPERTY, s)) {                cout << "Correctly got error when trying to get<String> of duration" << endl;        } else {                cerr << "ERROR AT " << __LINE__ << endl;        }        try {                cout << "dummy prop is " << e.get<String>(NONEXISTENT_PROPERTY) << endl;        } catch (Event::NoData bt) {                cout << "Correctly caught NoData when trying to get non existent property" << endl;        }        if (!e.get<String>(NONEXISTENT_PROPERTY, s)) {                cout << "Correctly got error when trying to get<String> of non existent property" << endl;        } else {                cerr << "ERROR AT " << __LINE__ << endl;        }        e.setFromString<Int>(DURATION_PROPERTY, "30");        cout << "duration is " << e.get<Int>(DURATION_PROPERTY) << endl;        e.setFromString<String>(ANNOTATION_PROPERTY, "This is my house");        cout << "annotation is " << e.get<String>(ANNOTATION_PROPERTY) << endl;        long durationVal;        if (e.get<Int>(DURATION_PROPERTY, durationVal))                cout << "duration is " << durationVal << endl;        else                cerr << "ERROR AT " << __LINE__ << endl;        if (e.get<String>(ANNOTATION_PROPERTY, s))                cout << "annotation is " << s << endl;        else                cerr << "ERROR AT " << __LINE__ << endl;	cout << "\nTesting persistence & setMaybe..." << endl;	e.setMaybe<Int>(SOME_INT_PROPERTY, 1);	if (e.get<Int>(SOME_INT_PROPERTY) == 1) {	    cout << "a. Correct: 1" << endl;	} else {	    cout << "a. ERROR: " << e.get<Int>(SOME_INT_PROPERTY) << endl;	}	e.set<Int>(SOME_INT_PROPERTY, 2, false);	e.setMaybe<Int>(SOME_INT_PROPERTY, 3);	if (e.get<Int>(SOME_INT_PROPERTY) == 3) {	    cout << "b. Correct: 3" << endl;	} else {	    cout << "b. ERROR: " << e.get<Int>(SOME_INT_PROPERTY) << endl;	}	e.set<Int>(SOME_INT_PROPERTY, 4);	e.setMaybe<Int>(SOME_INT_PROPERTY, 5);	if (e.get<Int>(SOME_INT_PROPERTY) == 4) {	    cout << "c. Correct: 4" << endl;	} else {	    cout << "c. ERROR: " << e.get<Int>(SOME_INT_PROPERTY) << endl;	}        cout << "\nTesting debug dump : " << endl;        e.dump(cout);        cout << endl << "dump finished" << endl;#if TEST_SPEED        cout << "Testing speed of Event..." << endl;        int i;        long j;        char b[20];        strcpy(b, "test");#define NAME_COUNT 500        PropertyName names[NAME_COUNT];        for (i = 0; i < NAME_COUNT; ++i) {            sprintf(b+4, "%d", i);            names[i] = b;        }        Event e1("note", 0);        int gsCount = 200000;        st = times(&spare);        for (i = 0; i < gsCount; ++i) {                e1.set<Int>(names[i % NAME_COUNT], i);        }        et = times(&spare);        cout << "Event: " << gsCount << " setInts: " << (et-st)*10 << "ms\n";        st = times(&spare);        j = 0;        for (i = 0; i < gsCount; ++i) {                if (i%4==0) sprintf(b+4, "%d", i);                j += e1.get<Int>(names[i % NAME_COUNT]);        }        et = times(&spare);        cout << "Event: " << gsCount << " getInts: " << (et-st)*10 << "ms (result: " << j << ")\n";                st = times(&spare);        for (i = 0; i < 1000; ++i) {                Event e11(e1);                (void)e11.get<Int>(names[i % NAME_COUNT]);        }        et = times(&spare);        cout << "Event: 1000 copy ctors of " << e1.getStorageSize() << "-byte element: "

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -