Пример #1
0
/******************************************************************************
 *	De-init Semaphore sub-module
 *
 *	Parameter:
 *		None
 *
 *	Return value:
 *		0					Success
 *****************************************************************************/
OSA_RESULT	osa_sem_release(void)
{
	list_t *plist;
	SemHandle_t *phandle;

    d3(printf("osa_sem_release:\n"));
	
    if( g_pSems ) {
        /* delete all open semaphores */
        plist = &(g_pSems->list);
        while( plist->next != plist->prev ) {
            phandle = list_entry(plist, SemHandle_t, list);

            osa_sem_delete( (OSA_HANDLE) phandle );
        }

        sem_destroy( &g_ListMux );

        memset(g_pSems, 0, sizeof(SemHandle_t));
        free(g_pSems);
        g_pSems = NULL;
    }

    d3(printf("osa_sem_release: end\n"));

	return 0;
}
Пример #2
0
/******************************************************************************
 *  Initialize Portable layer Thread functions
 *
 *  Parameter:
 *      NONE
 *  Return value:
 *      0                   successful
 *****************************************************************************/
OSA_RESULT  osa_t_init(void)
{
    struct sched_param  sparam;
    pid_t               mypid;

    d3(printf("osa_t_init:\n"));
    
    /* setup thread handle list */
    g_ThreadList = (ThreadHandle_t*) malloc( sizeof(ThreadHandle_t) );
    memset(g_ThreadList, 0, sizeof(ThreadHandle_t));
    INIT_LIST_HEAD( &(g_ThreadList->list) );
    g_ThreadList->id = 0;
    g_ThreadList->magic = OSA_T_MAGIC;

    /* create, set tid tsd */
    if( _osa_tid_key == -1 )
        _osa_tsd_create(&_osa_tid_key);
    _osa_tsd_set( &_osa_tid_key, (size_t) g_ThreadList);

    /* set my schedule policy ?*/
    #if 1
    mypid = getpid();
    sched_getparam(mypid,&sparam);
    sparam.sched_priority = (OSA_T_LNX_PRIORITY_MAX - OSA_T_LNX_PRIORITY_MIN + 1)/2;
    sched_setscheduler(mypid, SCHED_RR, &sparam);
    //sched_setscheduler(mypid,SCHED_OTHER,&sparam);
    #endif

    // setup thread signal actions
    _osa_t_setup_signal();

    d3(printf("osa_t_init: end\n"));
    
    return 0;
}
Пример #3
0
/******************************************************************************
 *	Deinit mutex sub-module
 *
 *	Parameter:
 *		None
 *
 *	Return value:
 *		0					Success
 *****************************************************************************/
OSA_RESULT	osa_mu_release(void)
{
	MutexHandle_t	*phandle;
    list_t          *plist;

	d3(printf( "osa_mu_release:\n"));

    if( g_pMutexs ) {
        plist = &(g_pMutexs->list);
        while( plist->next != plist->prev ) {
            phandle = list_entry( &(plist->next), MutexHandle_t, list);

            osa_mu_delete( (OSA_HANDLE) phandle);
        }

        sem_destroy( &g_ListMux );

        memset(g_pMutexs, 0, sizeof(MutexHandle_t));
        free(g_pMutexs);
        g_pMutexs = NULL;
    }

    d3(printf("osa_mu_release: end\n"));

	return 0;
}
Пример #4
0
/******************************************************************************
 *  Release Portable layer Thread enviroment
 *
 *  Parameter:
 *      NONE
 *  Return value:
 *      0                   successful
 *****************************************************************************/
OSA_RESULT  osa_t_release(void)
{
    list_t          *list;
    ThreadHandle_t  *handle;

    d3(printf("osa_t_release:\n"));

    if( g_ThreadList ) {
        /* stop all thread & delete thread handle list */
        list = &(g_ThreadList->list);
        while( list->next != list->prev ) {
            handle = list_entry(list->next, ThreadHandle_t, list);

            /* if it state isn't STOP then stop it */
            if( handle->state != OSA_TS_STOP ) {
                osa_t_kill((OSA_HANDLE) handle);
            }

            /* delete thread resource */
            osa_t_delete( (OSA_HANDLE) handle );
        }
    }

    d3(printf("osa_t_release: end\n"));
    
    return 0;
}
Пример #5
0
/******************************************************************************
 *	Create mutex
 *
 *	Parameter:
 *		hMu					[out] Mutex's handle
 *		mode				[in] create flags
 *
 *	Return value:
 *		0					Success
 *****************************************************************************/
OSA_RESULT	osa_mu_create(OSA_HANDLE *hMu, ru32 mode)
{
	MutexHandle_t *phandle;

    d3(printf("osa_mu_create: mode:%d\n", mode));
	
    phandle = (MutexHandle_t*) malloc(sizeof(MutexHandle_t));
	if( phandle == NULL ) {
        d1(printf("osa_mu_create: malloc fail\n"));
		return E_OSA_MEM;
	}
	memset(phandle, 0, sizeof(MutexHandle_t));

	INIT_LIST_HEAD( &(phandle->list) );
	phandle->magic = OSA_MU_MAGIC;
	pthread_mutex_init( &(phandle->handle), NULL );

	/* now insert into list */
    if( g_pMutexs ) {
        sem_wait( &(g_ListMux) );
        list_add( &(phandle->list), &(g_pMutexs->list) );
        sem_post( &(g_ListMux) );
    }

	*hMu = (OSA_HANDLE) phandle;

    d3(printf("osa_mu_create: end\n"));

	return 0;
}
Пример #6
0
/******************************************************************************
 *  Local: set thread specifice data
 *
 *  Parameter:
 *      threadvar               Thread's TSD
 *      value                   TSD
 *
 *  Return value:
 *      0                       Success
 *****************************************************************************/
static void _sig_suspend_handler(ri32 signo)
{
    ThreadHandle_t  *handle;
    ri32            ret;
    sigset_t        mask;

    handle = (ThreadHandle_t *) osa_t_self();
    if( _osa_t_checkHandle(handle) ) {
        d1(printf("_sig_suspend_handler: thread's handle error!\n"));
        return;
    }

    d3(printf("_sig_suspend_handler: id=%x\n", handle->id));

    ret = sem_trywait( &(handle->th_sem) );
    if( 0 != ret ) {
        d1(printf("_sig_suspend_handler: cant tyrwait semaphore!"));
        return ;
    }
        
    if( OSA_TO_SUSPEND == handle->op) {
        /* check current thread state */
        if (OSA_TS_RUN != handle->state) {
            d1(printf("_sig_suspend_handler: error thread state!\n"));
            sem_post( &(handle->th_sem) );
            return ;
        }

        sigemptyset(&mask);
        pthread_sigmask(SIG_BLOCK, &mask, &mask);
        sigdelset(&mask, THREAD_SIG_CONTINUE);

        handle->state = OSA_TS_SUSPEND;

        sem_post( &(handle->th_sem) );
        sem_post( &(handle->suspend_sem) );
        
        do {
            sigsuspend(&mask);
        } while ( OSA_TO_CONTINUE != handle->op );

        /* set state to RUNNING */
        sem_wait( &(handle->th_sem) );
        handle->state = OSA_TS_RUN;
        sem_post( &(handle->th_sem) );

        d3(printf( "_sig_suspend_handler: end\n"));
        
        return;
    }

    d2(printf("_sig_suspend_handler: error operation code.\n"));

    sem_post( &(handle->th_sem));
}
Пример #7
0
/******************************************************************************
 *	Initialize Semaphore sub-module
 *
 *	Parameter:
 *		None
 *
 *	Return value:
 *		0					Success
 *****************************************************************************/
OSA_RESULT	osa_sem_init(void)
{
    d3(printf("osa_sem_init:\n"));
	
    g_pSems = (SemHandle_t*) malloc(sizeof(SemHandle_t));
	g_pSems->magic = OSA_SEM_MAGIC;
	INIT_LIST_HEAD( &(g_pSems->list) );

	sem_init( &g_ListMux, 0, 1);

    d3(printf("osa_sem_init: end\n"));
	
	return 0;
}
Пример #8
0
static void veltranspose(float *vel,int ny,int nx,int nz)
{
    float *tmpvel=sf_floatalloc(ny*nx*nz);
    int nvel[2],ntmpvel[2];
    int i,iz,iy,ix;
    d3(ny,nx,nvel); d3(nx,nz,ntmpvel);
    for(i=0;i<ny*nx*nz;i++)
	tmpvel[i]=vel[i];
    for(iz=0;iz<nz;iz++)
	for(iy=0;iy<ny;iy++)
	    for(ix=0;ix<nx;ix++)
		vel[i3(iz,iy,ix,nvel)]=tmpvel[i3(iy,ix,iz,ntmpvel)];
    free(tmpvel); 
}
Пример #9
0
/******************************************************************************
 *  Resume a thread to run
 *
 *  Parameter:
 *      hTask                   [in] Thread's handle
 *
 *  Return value:
 *      0                       Success
 *****************************************************************************/
OSA_RESULT  osa_t_resume(OSA_HANDLE hTask)
{
    ThreadHandle_t  *handle;
    ri32            ret;

    handle = (ThreadHandle_t *) hTask;
    ret = _osa_t_checkHandle(handle);
    if( ret != 0 ) {
        d1(printf("osa_t_resume: given thread's handle error!\n"));
        return E_OSA_T_BADHANDLE;
    }

    d3(printf("osa_t_resume: ThreadID: %d\n", handle->id));

    sem_wait( &(handle->th_sem) );
    if( OSA_TS_STOP == handle->state ) {
        sem_post( &(handle->th_sem) );
        return E_OSA_T_NOSUSPEND;
    }

    if( (handle->suspend_count == 0) || (handle->state == OSA_TS_RUN) ) {
        sem_post( &(handle->th_sem) );
        return E_OSA_T_RUNNING;
    }
    
    handle->suspend_count --;
    if( handle->suspend_count > 0 ) {
        d2(printf("osa_t_resume: suspend count large than 2(%d)\n",
                  handle->suspend_count));
        sem_post( &(handle->th_sem) );

        return E_OSA_T_SUSPEND;
    }

    handle->op = OSA_TO_CONTINUE;
    ret = pthread_kill(handle->threadid, THREAD_SIG_CONTINUE);
    if ( 0 != ret ) {
        sem_post( &(handle->th_sem) );
        d1(printf("osa_t_resume: send THREAD_SIG_CONTINUE failed!\n"));
        return -1;
    }
    
    sem_post( &(handle->th_sem) );

    d3(printf( "osa_t_resume: end\n"));
    
    return 0;
}
Пример #10
0
/******************************************************************************
 *  Local: set thread specifice data
 *
 *  Parameter:
 *      threadvar               Thread's TSD
 *      value                   TSD
 *
 *  Return value:
 *      0                       Success
 *****************************************************************************/
static void _sig_kill_handler(ri32 signo)
{
    ThreadHandle_t *handle;

    d3(printf("_sgi_kill_handler:\n"));
    
    handle = (ThreadHandle_t *) osa_t_self();
    if( _osa_t_checkHandle(handle) ) {
        d1(printf("_sig_kill_handler: thread handle error!\n"));
        return;
    }

    sem_post( &(handle->kill_sem) );

    /* set state to STOP */
    sem_wait( &(handle->th_sem) );
    //d1(printf(">> set thread state to OSA_TS_STOP 4 (%5d)\n",
    //          osa_t_getid())); fflush(stdout);
    handle->state = OSA_TS_STOP;
    sem_post( &(handle->th_sem) );

    _osa_tsd_set( &_osa_tid_key, 0 );

    pthread_exit(0);
}
Пример #11
0
    void addTest()
    {
        csvsqldb::Duration d1(3, 1, 90, 17, 6, 45);
        d1.add(csvsqldb::Duration(5, 2, 1, 3, 7, 5));
        MPF_TEST_ASSERTEQUAL(8, d1.years());
        MPF_TEST_ASSERTEQUAL(3, d1.months());
        MPF_TEST_ASSERTEQUAL(91, d1.days());
        MPF_TEST_ASSERTEQUAL(20, d1.hours());
        MPF_TEST_ASSERTEQUAL(13, d1.minutes());
        MPF_TEST_ASSERTEQUAL(50, d1.seconds());

        csvsqldb::Duration d2(1, 2, 5);
        d2.add(d1);
        MPF_TEST_ASSERTEQUAL(9, d2.years());
        MPF_TEST_ASSERTEQUAL(5, d2.months());
        MPF_TEST_ASSERTEQUAL(96, d2.days());
        MPF_TEST_ASSERTEQUAL(20, d2.hours());
        MPF_TEST_ASSERTEQUAL(13, d2.minutes());
        MPF_TEST_ASSERTEQUAL(50, d2.seconds());
        MPF_TEST_ASSERTEQUAL(csvsqldb::Duration::Positive, d2.sign());

        csvsqldb::Duration d3(1, 2, 3, csvsqldb::Duration::Negative);
        MPF_TEST_EXPECTS(d3.add(d2), csvsqldb::DurationException);

        d3.add(csvsqldb::Duration(1, 2, 3, csvsqldb::Duration::Negative));
        MPF_TEST_ASSERTEQUAL(2, d3.years());
        MPF_TEST_ASSERTEQUAL(4, d3.months());
        MPF_TEST_ASSERTEQUAL(6, d3.days());
        MPF_TEST_ASSERTEQUAL(0, d3.hours());
        MPF_TEST_ASSERTEQUAL(0, d3.minutes());
        MPF_TEST_ASSERTEQUAL(0, d3.seconds());
        MPF_TEST_ASSERTEQUAL(csvsqldb::Duration::Negative, d3.sign());
    }
Пример #12
0
/******************************************************************************
 *  local used function: wrap function for create thread
 *
 *  Parameter:
 *      arg                 [in] input data
 *  Return value:
 *      
 *****************************************************************************/
static void *_osa_t_create(void *arg)
{
    ThreadParam_t   param;
    ThreadHandle_t  *pHandle;
    ri32            ret;

    d3(printf("_osa_t_create:\n"));
    
    // copy argument & free old argument
    memcpy( &param, arg, sizeof(ThreadParam_t) );
    free(arg);
    pHandle = param.handle;

    /* save thread handle to TSD */
    _osa_tsd_set(&_osa_tid_key, (size_t) pHandle);

    // resume caller thread
    sem_post(&(pHandle->th_sem));
    sem_post(&(pHandle->th_sem));

    pHandle->state = OSA_TS_RUN;

    /* call Thread function */
    ret = param.func(param.arg);

    sem_wait( &(pHandle->th_sem) );
    pHandle->state = OSA_TS_STOP;
    pHandle->ret   = ret;
    sem_post( &(pHandle->th_sem) );
    
    pthread_exit(0);

    return NULL;
}
Пример #13
0
int main() {
  Sales_data d1;
  Sales_data d2("0-201-78345-X");
  Sales_data d3("0-201-78345-X", 5, 2.5);
  Sales_data d4(std::cin);

  print(std::cout, d1) << std::endl;
  print(std::cout, d2) << std::endl;
  print(std::cout, d3) << std::endl;
  print(std::cout, d4) << std::endl;

  Sales_data total(std::cin);
  if (std::cin) {
    Sales_data trans(std::cin);
    while (std::cin) {
      if (total.isbn() == trans.isbn()) {
        total.combine(trans);
      } else {
        print(std::cout, total) << std::endl;
        total = trans;  // Use default copy constructor
      }
      read(std::cin, trans);
    }
    print(std::cout, total) << std::endl;
  } else {
    std::cerr << "No data!" << std::endl;
    return -1;
  }

  return 0;
}
Пример #14
0
std::auto_ptr<cpunit::TestRunner>
cpunit::TestExecutionFacade::get_test_runner(const bool robust, const double max_time) const {
  std::auto_ptr<TestRunner> leaf(new BasicTestRunner);

  if (robust) {
    CPUNIT_ITRACE("TestExecutionFacade::get_test_runner - Returning robust TestRunner");

    // For handling of extra, custom exceptions, insert your handler here,
    // and remember to modify the next decorator insertion...
    // std::auto_ptr<TestRunnerDecorator> d1(new MyCustomHandler);
    // d1->set_inner(leaf.release());

    // Add a layer of exception handling over the executing test runner
    std::auto_ptr<TestRunnerDecorator> d2(new RunAllTestRunner);
    d2->set_inner(leaf.release());

    // Add a layer of time taking
    std::auto_ptr<TestRunnerDecorator> d3(new TimeGuardRunner(max_time));
    d3->set_inner(d2.release());

    // Add a new layer of exception handling in case the max-time is exceeded
    std::auto_ptr<TestRunnerDecorator> d4(new RunAllTestRunner);
    d4->set_inner(d3.release());

    return std::auto_ptr<TestRunner>(d4.release());
  } else {
    CPUNIT_ITRACE("TestExecutionFacade::get_test_runner - Returning BasicTestRunner");

    // Add a layer of time taking over the executing test runner
    std::auto_ptr<TestRunnerDecorator> d1(new TimeGuardRunner(max_time));
    d1->set_inner(leaf.release());

    return std::auto_ptr<TestRunner>(d1.release());
  }
}
Пример #15
0
void
RelativeDateUnitTest::test_operators_general_valid()
{
 
	RelativeDateUnit d1("1Y");
	RelativeDateUnit d2("1Y");
	 

	//test: RelativeDateUnit::virtual Bool operator==(const RelativeDateUnit& other) const;
	CPPUNIT_ASSERT(d1 == d2);
	 
	//test: RelativeDateUnit::virtual Bool operator<(const RelativeDateUnit& other)  const ;
	//test: RelativeDateUnit::virtual Bool operator!=(const RelativeDateUnit& other)  const ;
	RelativeDateUnit d3 ("2Y");
	CPPUNIT_ASSERT(d1 < d3);
	CPPUNIT_ASSERT(d1 !=  d3);

    //test: RelativeDateUnit::virtual Bool operator<=(const RelativeDateUnit& other) const ;
	CPPUNIT_ASSERT(d1 <= d2);
	CPPUNIT_ASSERT(d1 <= d3);
     
    //test: RelativeDateUnit::virtual Bool operator>(const RelativeDateUnit& other) const  ;
	CPPUNIT_ASSERT(d3 > d1);

    //test: RelativeDateUnit::virtual Bool operator>=(const RelativeDateUnit& other) const ;
	CPPUNIT_ASSERT(d1 >= d2);
	CPPUNIT_ASSERT(d3 >= d1);

}
Пример #16
0
/******************************************************************************
 *  Initialize condition-variable sub-system
 *
 *  Parameter:
 *      None
 *
 *  Return value:
 *      0                       Success
 *****************************************************************************/
OSA_RESULT   osa_cv_init(void)
{
    d3(printf("osa_cv_init:\n"));
        
    g_CvList = (CvHandle_t*) malloc(sizeof(CvHandle_t));
    memset(g_CvList, 0, sizeof(CvHandle_t));

    INIT_LIST_HEAD( &(g_CvList->list) );
    g_CvList->magic = OSA_CV_MAGIC;

    sem_init(&g_ListMux, 0, 1);

    d3(printf("osa_cv_init: end\n"));
    
    return 0;
}
Пример #17
0
TEST_F(ItemDataTest, UnknownFields)
{
  unsigned char u1v[] = {10, 11, 33, 57};
  unsigned char u2v[] = {92, 77, 76, 40, 65, 66};
  unsigned char u3v[] = {1};

  CItemData d1, d2;

  ASSERT_EQ(0, d1.NumberUnknownFields());
  d1.SetUnknownField(CItemData::UNKNOWN_TESTING, sizeof(u1v), u1v);
  d1.SetUnknownField(CItemData::UNKNOWN_TESTING, sizeof(u2v), u2v);
  d1.SetUnknownField(CItemData::UNKNOWN_TESTING, sizeof(u3v), u3v);
  EXPECT_EQ(3, d1.NumberUnknownFields());

  EXPECT_NE(d1, d2);
  d2 = d1;
  EXPECT_EQ(d1, d2);
  CItemData d3(d1);
  EXPECT_EQ(d1, d3);

  // Getting Unknown Fields is done by private
  // member functions, which make sense considering
  // how they're processed. Worth exposing an API
  // just for testing, TBD.
}
      void TestEnsembleAssociation::testAjouter2() 
      {

        EnsembleAssociation<A> ensemble ;
        
        Composition<D> d1(new D()) ;
        Composition<D> d2(new D()) ;
        Composition<D> d3(new D()) ;
        
        ensemble.Ajouter(d1) ;
        ensemble.Ajouter(d2) ;
        ensemble.Ajouter(d3) ;

        CPPUNIT_ASSERT(ensemble.Contient(d1)) ;
        CPPUNIT_ASSERT(ensemble.Contient(d2)) ;
        CPPUNIT_ASSERT(ensemble.Contient(d3)) ;
        
        EntierPositif nombre(0) ;
        
        for(IterateurEnsembleAssociation<A> a(ensemble) ;
            a.Valide() ;
            ++a)
        {
          ++nombre ;
        }

        CPPUNIT_ASSERT(nombre == 3) ;

      }
Пример #19
0
TEST(DictionarySerializationTest, DifferentPropertiesNoReference) {
	AmfDictionary d(false, false);
	AmfDictionary d2(true, false);
	AmfDictionary d3(true, true);

	d.insert(AmfBool(true), AmfUndefined());
	d2.insert(AmfBool(true), AmfUndefined());
	d3.insert(AmfBool(true), AmfUndefined());

	SerializationContext ctx;
	isEqual({ 0x11, 0x03, 0x00, 0x03, 0x00 }, d.serialize(ctx));
	isEqual({
		0x11, 0x03, 0x00,
		0x06, 0x09, 0x74, 0x72, 0x75, 0x65,
		0x00
	}, d2.serialize(ctx));
	isEqual({
		0x11, 0x03, 0x01,
		0x06, 0x00,
		0x00
	}, d3.serialize(ctx));
	isEqual({ 0x11, 0x00 }, d.serialize(ctx));
	isEqual({ 0x11, 0x02 }, d2.serialize(ctx));
	isEqual({ 0x11, 0x04 }, d3.serialize(ctx));
}
Пример #20
0
int main(void)
{
	static const struct st3 a = {1, 2, 3, 4, 5, 6};

	l1(100);
	l2(100, 200);
	l3(100, 200, 300);
	l4(100, 200, 300, 400);
	l5(100, 200, 300, 400, 500);
	l6(100, 200, 300, 400, 500, 600);
	l7(100, 200, 300, 400, 500, 600, 700);
	l8(100, 200, 300, 400, 500, 600, 700, 800);

	d1();
	d2(43);
	d3(100, 200);
	d4(a);
	d5('a', 43, a);
	d6('a', 1);

	c1(44);
	c2(100, 'a', 3.4);
	c3(200, 2.777, 'q');
	c4(200, 1);
	c5(1.1, 2.2);
	c6(1.23, 45.6);
	c7('z', 0x200);

	a1('a');
	a2(10);
	a3(20);
	a4(102030405060LL);

	b1('a', 20);
	b2(30, 'b');
	b3(10, 20, 30, 40, 50, 60);

	s1(sx);
	s1p(&sx);
	s2(sy);
	s3(sz);
	s4(sq);
	s5(sa);
	s6(sb);

	r1();
	r3();
	r4();

	q1(200, sx);
	q2(300, 't', sx);
	q3(400, 410, sy);
	q4(500, 510, sq);
	q5(600, 610, 'z', 'q', sq);

	real1("fresh air");
	real2();

	return 0;
}
Пример #21
0
//Testing Suite for Dice Class
void unit1(){
    ofstream fout;
    fout.open("P2_Lee_Output.txt", ios::out | ios::app);
    Dice d1;                    //default of 6 sides, 2 dice
    Dice d2(4, 1);              //4 sides , 1 dice in set
    Dice d3(8, 4);              //8 sides, 4 dice in set
    Dice d4(6,0);               //No dice in the set

    cout <<"Testing the Dice class" << endl;
    cout <<"outputting to file......" << endl;

    d1.roll();
    fout <<"Test Suite 1: Default parameters of 6 sides and 4 dice in the set."
    << endl << "Values: " << right << setw(7) << d1;

    d2.roll();
    fout <<"Test Suite 2: Parameters of 4 sides and 1 di in the set."
    << endl << "Values: " << right << setw(7) << d2;

    d3.roll();
    fout <<"Test Suite 3: Parameters of 8 sides and 4 dice in the set."
    << endl << "Values: "  << right << setw(7) << d3;

    d4.roll();
    fout <<"Test Suite 4: Parameters of 6 sides and 0 dice in the set."
    << endl << "Values: "  << right << setw(7) << d4;

    fout << "Test Suite 5: Random Range Test, using 6-sided dice " << endl;
    for (int j = 0; j < 5; ++j){
        d1.roll();
        fout << "Values: " << right << setw(7) << d1;
    }
}
Пример #22
0
static void dda_init(const BezierPath::Point& p0,
		     const BezierPath::Point& p1,
		     const BezierPath::Point& p2,
		     const BezierPath::Point& p3,
		     int subdivisions,
										 vector2d<BezierPath::Coord>& dd1,
										 vector2d<BezierPath::Coord>& dd2,
										 vector2d<BezierPath::Coord>& dd3)
{
  vector2d<BezierPath::Coord> d0(p0.x(), p0.y());
  vector2d<BezierPath::Coord> d1(p1.x(), p1.y());
  vector2d<BezierPath::Coord> d2(p2.x(), p2.y());
  vector2d<BezierPath::Coord> d3(p3.x(), p3.y());
  vector2d<BezierPath::Coord> c = (d1 - d0) * 3;
  vector2d<BezierPath::Coord> b = (d2 - d1) * 3 - c;
  vector2d<BezierPath::Coord> a = d3 - b - c - d0;
  double delta = 1.0 / (1 << subdivisions);
  double delta_2 = delta * delta;
  double delta_3 = delta_2 * delta;
  a *= delta_3;
  b *= delta_2;
  c *= delta;
  dd1 = a + b + c; 
  dd2 = a * 6 + b * 2;
  dd3 = a * 6;
}
Пример #23
0
void testCompare()
{
    // Date1 = Date2
    vmime::datetime d1(2005, 4, 22, 14, 6, 0, vmime::datetime::GMT2);
    vmime::datetime d2(2005, 4, 22, 10, 6, 0, vmime::datetime::GMT_2);

    VASSERT_EQ("1.1", true,  d1 == d2);
    VASSERT_EQ("1.2", false, d1 != d2);
    VASSERT_EQ("1.3", true,  d1 <= d2);
    VASSERT_EQ("1.4", false, d1 <  d2);
    VASSERT_EQ("1.5", true,  d1 >= d2);
    VASSERT_EQ("1.6", false, d1 >  d2);

    // Date1 < Date2
    vmime::datetime d3(2005, 4, 22, 14, 6, 0);
    vmime::datetime d4(2005, 4, 22, 15, 6, 0);

    VASSERT_EQ("2.1", false, d3 == d4);
    VASSERT_EQ("2.2", true,  d3 != d4);
    VASSERT_EQ("2.3", true,  d3 <= d4);
    VASSERT_EQ("2.4", true,  d3 <  d4);
    VASSERT_EQ("2.5", false, d3 >= d4);
    VASSERT_EQ("2.6", false, d3 >  d4);

    // Date1 > Date2
    vmime::datetime d5(2005, 4, 22, 15, 6, 0);
    vmime::datetime d6(2005, 4, 22, 14, 6, 0);

    VASSERT_EQ("3.1", false, d5 == d6);
    VASSERT_EQ("3.2", true,  d5 != d6);
    VASSERT_EQ("3.3", false, d5 <= d6);
    VASSERT_EQ("3.4", false, d5 <  d6);
    VASSERT_EQ("3.5", true,  d5 >= d6);
    VASSERT_EQ("3.6", true,  d5 >  d6);
}
Пример #24
0
    void initB() {
        this->clearAppend(this->m_csB);

        R1Variable<T> d1(1), d2(2), d3(3), d4(4), d5(5), d6(6);

        this->m_csB.addConstraint(d1 * d2 == d5);
        this->m_csB.addConstraint(d1 * d3 == d6);
        this->m_csB.addConstraint(d5 * d6 == d4);

        this->m_csB.swap_AB_if_beneficial();

        // witness always consistent
        this->m_witnessB.assignVar(d1, T(m_d1));
        this->m_witnessB.assignVar(d2, T(m_d2));
        this->m_witnessB.assignVar(d3, T(m_d3));
        this->m_witnessB.assignVar(d4, T(m_d1 * m_d1 * m_d2 * m_d3));
        this->m_witnessB.assignVar(d5, T(m_d1 * m_d2));
        this->m_witnessB.assignVar(d6, T(m_d1 * m_d3));

        // public inputs may be inconsistent
        this->m_inputB.assignVar(d1, T(m_d1));
        this->m_inputB.assignVar(d2, T(m_d2));
        this->m_inputB.assignVar(d3, T(m_d3));
        this->m_inputB.assignVar(d4, T(m_d4));

        this->finalize(this->m_csB);
    }
Пример #25
0
static void tst5() {
    std::cout << "--------------------------------\n";    
    imdd_manager m;
    imdd_ref d1(m), d2(m), d3(m);
    std::cout.flush();
    d1 = m.mk_empty(3);
    add_triple(m, d1, 5, 100, 10, 20, 3, 10);
    std::cout << mk_ll_pp(d1,m) << std::endl;
    add_triple(m, d1, 5, 100, 34, 50, 98, 110);
    std::cout << mk_ll_pp(d1,m) << std::endl;
    unsigned vals[3] = {6, 8, 3};
    SASSERT(!m.contains(d1, 3, vals));
    add_triple(m, d1, 6, 25, 8, 30, 14, 50);
    std::cout << mk_ll_pp(d1,m) << std::endl;
    SASSERT(!m.contains(d1, 3, vals));
    unsigned vars[2] = {0, 2};
    d2 = d1;
    d3 = d1;
    m.mk_filter_identical(d1, d1, 2, vars);
    vars[1] = 1;
    std::cout << "d1:\n" << mk_ll_pp(d1,m) << "\n";
    m.mk_filter_identical(d2, d2, 2, vars);
    std::cout << "d2:\n" << mk_ll_pp(d2,m) << "\n";
    vars[0] = 1;
    vars[1] = 2;
    m.mk_filter_identical(d3, d3, 2, vars);
    std::cout << "d3:\n" << mk_ll_pp(d3,m) << "\n";
}
Пример #26
0
static void tst2() {
    std::cout << "--------------------------------\n";    
    imdd_manager m;
    imdd_ref d1(m), d2(m), d3(m);
    d1 = m.mk_empty(3);
    add_triple(m, d1, 10, 20, 11, 21, 12, 22);
    add_triple(m, d1, 30, 40, 31, 41, 32, 42);
    d2 = m.mk_empty(3);
    add_triple(m, d2, 15, 22, 15, 23, 7, 18);
    add_triple(m, d2, 28, 42, 29, 39, 34, 46);
    add_triple(m, d2, 28, 42, 29, 39, 100, 200);
    add_triple(m, d2, 28, 42, 50, 60, 100, 200);
    std::cout << mk_ll_pp(d1, m) << "\n";
    std::cout << mk_ll_pp(d2, m) << "\n";
    m.mk_union(d1, d2, d3);
    SASSERT(m.subsumes(d3, d1));
    SASSERT(m.subsumes(d3, d2));
    SASSERT(!m.subsumes(d1, d3));
    SASSERT(!m.subsumes(d2, d3));
    std::cout << "d3: " << d3.get() << "\n" << mk_ll_pp(d3, m) << "\n";
    m.mk_union_dupdt(d1, d2, false);
    std::cout << "d1: " << d1.get() << "\n" << mk_ll_pp(d1, m) << "\n";
    SASSERT(m.is_equal(d1, d3));
    SASSERT(!m.is_equal(d2, d3));
    SASSERT(!m.is_equal(d2, d1));
    std::cout << "memory(d1): " << m.memory(d1) << "\n";
}
Пример #27
0
 void test_operators()
 {
     xlnt::date d1(2016, 7, 16);
     xlnt::date d2(2016, 7, 16);
     xlnt::date d3(2016, 7, 15);
     xlnt_assert_equals(d1, d2);
     xlnt_assert_differs(d1, d3);
 }
TEST(Decimal128Test, TestDecimal128IsNaN) {
    Decimal128 d1("NaN");
    Decimal128 d2("10.5");
    Decimal128 d3("Inf");
    ASSERT_TRUE(d1.isNaN());
    ASSERT_FALSE(d2.isNaN());
    ASSERT_FALSE(d3.isNaN());
}
int main() {
    //Derived1 d1;    // 无法生成默认的构造函数,析构函数
    int data = 0;
    Derived2 d2(data);
    Derived2 d3(data);
  //  Derived2 d4(d2);  // ostream 无法复制
  //  d3 = d2;          // int&和const int无法赋值
    return 0;
}
Пример #30
0
 void formatTest()
 {
     csvsqldb::Duration d1(3, 1, 90, 17, 6, 45);
     MPF_TEST_ASSERTEQUAL("P3Y1M90DT17H6M45S", d1.format());
     csvsqldb::Duration d2(1, 2, 5);
     MPF_TEST_ASSERTEQUAL("P1Y2M5D", d2.format());
     csvsqldb::Duration d3(1, 2, 5, 17, 6, 45);
     MPF_TEST_ASSERTEQUAL("P1Y2M5DT17H6M45S", d3.format());
 }