Пример #1
0
void testTime()
{
  String test = Time::toString(123 * 1000, _T("%Y-%m-%d %H:%M:%S"), true);
  ASSERT(test == _T("1970-01-01 00:02:03"));

  {
    Time time(123LL * 1000, true);
    ASSERT(time.toString(_T("%Y-%m-%d %H:%M:%S")) == test);
    ASSERT(time.year == 1970);
    ASSERT(time.month == 1);
    ASSERT(time.day == 1);
    ASSERT(time.hour == 0);
    ASSERT(time.min == 2);
    ASSERT(time.sec == 3);
  }

  int64 now = Time::time();
  Time time(now);
  ASSERT(time.toTimestamp() == now);
  Time time2(time);
  time2.toLocal();
  ASSERT(time == time2);
  ASSERT(time2.toTimestamp() == now);

  Time timeUtc(time);
  timeUtc.toUtc();
  ASSERT(timeUtc != time);
  ASSERT(timeUtc.toTimestamp() == now);
  Time timeUtc2(timeUtc);
  timeUtc2.toUtc();
  ASSERT(timeUtc != time);
  ASSERT(timeUtc2 == timeUtc);
  ASSERT(timeUtc2.toTimestamp() == now);
}
void VendorHandler::pass2to1() {
    setValid1(true);
    setName1(name2());
    setStreet1(street2());
    setCity1(city2());
    setState1(state2());
    setRegion1(region2());
    setTime1(time2());
    setZip1(zip2());
    setPrice1(price2());
}
Пример #3
0
int main() {

	Time time1(10, 20); //Ok.

	try {
		Time time2(59, 20);
	}
	catch (std::exception s) {
		std::cout << s.what() << "\n";
	}
	
	return 0;
}
Пример #4
0
TEST_F( TimeTests, TickTime_Constructors_And_Comparisons )
{
	STickTime time1( 5 );
	STickTime time2( time1 );
	STickTime time3 = time2;

	ASSERT_TRUE( time1 == time2 && time2 == time3 );
	ASSERT_TRUE( time1.Get_Ticks() == 5 );
	ASSERT_FALSE( time1 != time2 );

	STickTime time4( 3 );

	ASSERT_TRUE( time4 < time1 );
}
BOOL COptionsStats::OnInitDialog() 
{
	CPropertyPage::OnInitDialog();

	CTime time(CGetSetOptions::GetTotalDate());
	m_eAllDate = time.Format("%m/%d/%Y %I:%M %p");
	m_eAllCopies.Format(_T("%d"), CGetSetOptions::GetTotalCopyCount());
	m_eAllPastes.Format(_T("%d"), CGetSetOptions::GetTotalPasteCount());

	CTime time2(CGetSetOptions::GetTripDate());
	m_eTripDate = time2.Format("%m/%d/%Y %I:%M %p");
	m_eTripCopies.Format(_T("%d"), CGetSetOptions::GetTripCopyCount());
	m_eTripPastes.Format(_T("%d"), CGetSetOptions::GetTripPasteCount());

	m_eClipsSent.Format(_T("%d"), theApp.m_lClipsSent);
	m_eClipsRecieved.Format(_T("%d"), theApp.m_lClipsRecieved);
	m_eLastStarted = theApp.m_oldtStartUp.Format(_T("%m/%d/%y %I:%M:%S"));
	if(theApp.m_oldtStartUp.GetHour() > 12)
		m_eLastStarted += " PM";
	else
		m_eLastStarted += " AM";

	COleDateTimeSpan span = COleDateTime::GetCurrentTime() - theApp.m_oldtStartUp;

	CString csSpan;
	csSpan.Format(_T("  -  %d.%d.%d (D.H.M)"), (long)span.GetTotalDays(), span.GetHours(), span.GetMinutes());
	m_eLastStarted += csSpan;

	try
	{
		m_eSavedCopies.Format(_T("%d"), theApp.m_db.execScalar(_T("SELECT COUNT(lID) FROM Main")));
		m_eSavedCopyData.Format(_T("%d"), theApp.m_db.execScalar(_T("SELECT COUNT(lID) FROM Data")));
	}
	CATCH_SQLITE_EXCEPTION
	
	__int64 size = FileSize(GetDBName());			

	const int MAX_FILE_SIZE_BUFFER = 255;
	TCHAR szFileSize[MAX_FILE_SIZE_BUFFER];
	StrFormatByteSize(size, szFileSize, MAX_FILE_SIZE_BUFFER);

	m_eDatabaseSize = szFileSize;

	UpdateData(FALSE);

	theApp.m_Language.UpdateOptionStats(this);
		
	return TRUE;
}
Пример #6
0
time_t
timegm(
	struct tm * tmp
	)
{
	register time_t			t;
	int				okay;

	tmp->tm_isdst = 0;
	t = time2(tmp, &okay, 0);
	if (okay || tmp->tm_isdst < 0)
		return t;

	return WRONG;
}
Пример #7
0
static time_t
time1(
	struct tm * tmp
	)
{
	register time_t			t;
	int				okay;

	if (tmp->tm_isdst > 1)
		tmp->tm_isdst = 1;
	t = time2(tmp, &okay, 1);
	if (okay || tmp->tm_isdst < 0)
		return t;

	return WRONG;
}
Пример #8
0
TEST_F( TimeTests, TickTime_Arithmetic )
{
	STickTime time1( 1 );
	STickTime time2( 2 );

	STickTime time3 = time1 + time2;
	STickTime time4( time1 );
	time4 += time2;

	ASSERT_TRUE( time3 == time4 );
	ASSERT_TRUE( time3.Get_Ticks() == 3 );

	time4 -= time2;
	ASSERT_TRUE( time4 == time1 );

	STickTime time5 = time3 - time2;
	ASSERT_TRUE( time5 == time1 );
}
Пример #9
0
int main(int argc, char const *argv[])
{
	Time time1(4, 20);
	// time1.hour; // private
	std::cout << time1 << std::endl;

	Time time2(5, 30);
	std::cout << time2 << std::endl;

	Time time3 = time1 + time2;
	std::cout << time3 << std::endl;

	Time time4 = time1 - time2;
	std::cout << time4 << std::endl;

	Time time5 =0.5 * time1;
	std::cout << time5 << std::endl;
	return 0;
}
Пример #10
0
   void
   DateTimeTests::Test()
   {
      // Handles dates starting 1970.
      DateTime time1 (1960,01,01, 00, 00, 00);
      if (time1.ToInt() != 0)
         throw;

      DateTime time2 (1970,01,01, 00, 00, 00);
      if (time2.ToInt() != 0)
         throw;

      DateTime time3 (1970,01,01, 00, 00, 05);
      if (time3.ToInt() != 5)
         throw;

      DateTime time4 (1970,01,02, 00, 00, 00);
      if (time4.ToInt() != 86400) // seconds of a day.
         throw;
      
      DateTime time5 (1971,01,01, 00, 00, 00);
      if (time5.ToInt() != 365 * 24 * 3600) // seconds of a day.
         throw;

      DateTime time6 (2009,05,14, 22, 02, 00);
      if (time6.ToInt() != 1242338520)
         throw;

      DateTime time7 (2020,12,31, 23, 59, 00);
      if (time7.ToInt() != 1609459140 )
         throw;

      DateTime timea (2030,01,01, 00, 00, 00);
      if (timea.ToInt() == 0)
         throw;


   }
Пример #11
0
void TablesWizard::numberOfDayChanged()
{
    int day = ui->m_dayCount->value();
    m_editors.clear();
    ui->tableWidget->clear();
    ui->tableWidget->setRowCount(0);
    ui->tableWidget->setColumnCount(0);
    ui->tableWidget->clearContents();
    ui->tableWidget->insertColumn(0);
    ui->tableWidget->insertColumn(1);
    QStringList header;
    header << tr("Start Time") << tr("End Time");
    ui->tableWidget->setHorizontalHeaderLabels(header);
    ui->tableWidget->horizontalHeader()->setStretchLastSection(true);
    for(int i = 0; i < day; i++)
    {
        ui->tableWidget->insertRow(i);
        QTableWidgetItem* start = new QTableWidgetItem();
        QTableWidgetItem* end = new QTableWidgetItem();

        ui->tableWidget->setItem(i,0,start);
        ui->tableWidget->setItem(i,1,end);

        QTime time(8,0);
        QTime time2(20,0);
        auto timeEdit = new QTimeEdit(time);
        auto timeEdit2 = new QTimeEdit(time2);

        m_editors.insert(timeEdit,start);
        m_editors.insert(timeEdit2,end);
        ui->tableWidget->setCellWidget(i,0,timeEdit);
        ui->tableWidget->setCellWidget(i,1,timeEdit2);

        start->setFlags(Qt::ItemIsEnabled | Qt::ItemIsEditable | Qt::ItemIsSelectable);
        end->setFlags(Qt::ItemIsEnabled | Qt::ItemIsEditable | Qt::ItemIsSelectable);
    }
}
Пример #12
0
void KNDdeTorusCollocation::jacobian(KNSparseMatrix& A, KNArray1D< KNVector* > Avar, KNVector& rhs, KNVector& par, KNVector& /*sol*/, KNArray1D<size_t>& var)
{
  A.clear();
  rhs.clear();
  for (size_t r = 0; r < var.size(); r++) Avar(r)->clear();
  // rhs doesn't need to be cleared

  // creates kk, ee, rr & interpolates p_xx & gets p_tau
//   init(sol, par);
  // builds up the structure of the sparse matrix
  for (size_t idx = 0; idx < time1.size(); ++idx)
  {
    const size_t lend = NDIM * (rr(ee((NTAU+1)*(ndeg1+1)*(ndeg2+1)-1,idx),idx) + 1);
    for (size_t p = 0; p < NDIM; p++) A.newLine(lend);
  }

  // the right-hand side
  sys->p_rhs(p_fx, time1, p_xx, par, 0);
  for (size_t idx = 0; idx < time1.size(); ++idx)
  {
    for (size_t p = 0; p < NDIM; p++) 
    {
      rhs(p + NDIM*idx) = par(0) * p_fx(p,idx) - p_xx(p, NTAU, idx) - par(RHO) * p_xx(p, NTAU + 1, idx);
    }
  }

  // derivatives w.r.t the parameters
  for (size_t r = 0; r < var.size(); r++)
  {
    KNVector& deri = *Avar(r);
    deri.clear();
//!!!!!!!!!!!!!!!!!
//!BEGIN w.r.t the period
//!!!!!!!!!!!!!!!!!
    if (var(r) == 0)
    {
      for (size_t idx = 0; idx < time1.size(); ++idx)
      {
        for (size_t p = 0; p < NDIM; p++) deri(p + NDIM*idx) = -p_fx(p,idx);
      }
      sys->p_dtau(p_dtau, time1, par, 0);
      for (size_t k = 0; k < NTAU; k++)
      {
        size_t nx = 1, vx = k, np = 0, vp = 0;
        sys->p_deri(p_dfx, time1, p_xx, par, 0, nx, &vx, np, &vp, p_dummy);
        for (size_t idx = 0; idx < time1.size(); ++idx)
        {
          for (size_t p = 0; p < NDIM; p++)
          {
            for (size_t q = 0; q < NDIM; q++)
            {
              const double d = p_tau(k,idx) / par(0) - p_dtau(k,idx);
              deri(p + NDIM*idx) -= p_dfx(p, q, idx) * d * (p_xx(q, NTAU + 2 * (k + 1), idx) + par(RHO) * p_xx(q, NTAU + 2 * (k + 1) + 1, idx));
            }
          }
        }
      }
    }
    else
//!!!!!!!!!!!!!!!!!
//!END w.r.t the period
//!!!!!!!!!!!!!!!!!
//
//!!!!!!!!!!!!!!!!!
//!BEGIN w.r.t the ordinary parameters
//!!!!!!!!!!!!!!!!!
    // derivatives w.r.t. the real parameters
    if (var(r) < NPAR)
    {
      size_t nx = 0, vx = 0, np = 1, vp = var(r);
      sys->p_deri(p_dfp, time1, p_xx, par, 0, nx, &vx, np, &vp, p_dummy);
      for (size_t idx = 0; idx < time1.size(); ++idx)
      {
        for (size_t p = 0; p < NDIM; p++) deri(p + NDIM*idx) = - par(0) * p_dfp(p, 0, idx);
      }
    }
    else
//!!!!!!!!!!!!!!!!!
//!END w.r.t the ordinary parameters
//!!!!!!!!!!!!!!!!!
//
//!!!!!!!!!!!!!!!!!
//!BEGIN w.r.t the rotation number
//!!!!!!!!!!!!!!!!!
    if (var(r) == RHO)
    {
      for (size_t idx = 0; idx < time1.size(); ++idx)
      {
        for (size_t p = 0; p < NDIM; p++) deri(p + NDIM*idx) = p_xx(p, NTAU + 1, idx);
      }
      sys->p_dtau(p_dtau, time1, par, 0);
      for (size_t k = 0; k < NTAU; k++)
      {
        const size_t nx = 1, vx = k, np = 0, vp = 0;
        sys->p_deri(p_dfx, time1, p_xx, par, 0, nx, &vx, np, &vp, p_dummy);
        for (size_t idx = 0; idx < time1.size(); ++idx)
        {
          const double d = -p_tau(k, idx);
          for (size_t p = 0; p < NDIM; p++)
          {
            for (size_t q = 0; q < NDIM; q++)
            {
              deri(p + NDIM*idx) -= p_dfx(p, q, idx) * d * p_xx(q, NTAU + 2 * (k + 1) + 1, idx);
            }
          }
        }
      }
    }
//!!!!!!!!!!!!!!!!!
//!END w.r.t the rotation number
//!!!!!!!!!!!!!!!!!
    else std::cout << "Jac:NNN\n";
  }
  // fill the matrix
  for (size_t k = 0; k < NTAU + 1; k++)
  {
    if (k != 0)
    {
      // evaluate the solution
      const size_t nx = 1, vx = k - 1, np = 0, vp = 0;
      sys->p_deri(p_dfx, time1, p_xx, par, 0, nx, &vx, np, &vp, p_dummy);
    }

    for (size_t idx = 0; idx < time1.size(); ++idx)
    {
      double tk1, tk2;
      if (k != 0)
      {
        tk1 = time1(idx) - p_tau(k-1,idx) / par(0);
        tk2 = time2(idx) - par(RHO) * p_tau(k-1,idx) / par(0);
      } else
      {
        tk1 = time1(idx);
        tk2 = time2(idx);
      }
      const double c1 = nint1 * tk1 - floor(nint1 * tk1);
      const double c2 = nint2 * tk2 - floor(nint2 * tk2);

      // the real jacobian
      for (size_t l2 = 0; l2 < ndeg2 + 1; l2++)
      {
        for (size_t l1 = 0; l1 < ndeg1 + 1; l1++)
        {
          const size_t idxK = idxkk(l1, l2, k);
          if (k != 0)
          {
            const double cf = poly_lgr_eval(mesh1, l1, c1) * poly_lgr_eval(mesh2, l2, c2);
            for (size_t p = 0; p < NDIM; p++)
            {
              for (size_t q = 0; q < NDIM; q++)
              {
                // jacobian of rhs
                A.writeIndex(p + NDIM*idx, q + NDIM*rr(idxK, idx)) = static_cast<int>(q + NDIM * kk(idxK, idx));
                A.writeData(p + NDIM*idx, q + NDIM*rr(idxK, idx)) -= cf * par(0) * p_dfx(p, q, idx);
              }
            }
          }
          else
          {
            const double cf1 = poly_dlg_eval(mesh1, l1, c1) * nint1 * poly_lgr_eval(mesh2, l2, c2);
            const double cf2 = poly_lgr_eval(mesh1, l1, c1) * poly_dlg_eval(mesh2, l2, c2) * nint2;
            for (size_t p = 0; p < NDIM; p++)
            {
              for (size_t q = 0; q < NDIM; q++)
              {
                // derivative part of the jacobian
                A.writeIndex(p + NDIM*idx, q + NDIM*rr(idxK, idx)) = static_cast<int>(q + NDIM * kk(idxK, idx));
                if (p == q)
                  A.writeData(p + NDIM*idx, q + NDIM*rr(idxK, idx)) += cf1 + par(RHO) * cf2;
              }
            }
          }
          // error check
          if (kk(idxK, idx) > (ndeg1*nint1)*(ndeg2*nint2)) std::cout << "D" << kk(idxK, idx);
        }
      }
    }
  }
}
Пример #13
0
/***********************************************************************//**
 * @brief Test GTime
 ***************************************************************************/
void TestGObservation::test_time(void)
{
    // Test void constructor
    test_try("Void constructor");
    try {
        GTime time;
        test_try_success();
    }
    catch (std::exception &e) {
        test_try_failure(e);
    }

    // Test copy constructor
    test_try("Copy constructor");
    try {
        GTime time;
        GTime time2(time);
        test_try_success();
        test_assert(time == time2, "Time differs after using copy constructor.");
    }
    catch (std::exception &e) {
        test_try_failure(e);
    }

    // Test time constructor (seconds)
    test_try("Time constructor (seconds)");
    try {
        GTime time(1800.01);
        test_try_success();
        test_value(time.secs(), 1800.01);
        test_value(time.days(), 1800.01/86400.0);
    }
    catch (std::exception &e) {
        test_try_failure(e);
    }

    // Test time constructor (days)
    test_try("Time constructor (days)");
    try {
        GTime time(41.7, "days");
        test_try_success();
        test_value(time.days(), 41.7);
        test_value(time.secs(), 41.7*86400.0);
    }
    catch (std::exception &e) {
        test_try_failure(e);
    }

    // Test access methods
    double mjd_ref = 55197.000766018518519;
    double jd_ref  = 2455197.500766018518519;
    double t       = 123456.789;
    GTime time(t);
    test_value(time.jd(), t/86400.0 + jd_ref);
    test_value(time.mjd(), t/86400.0 + mjd_ref);
    test_value(time.secs(), t);
    test_value(time.days(), t/86400.0);

    // Test set method
    time.jd(57.9);
    test_value(time.jd(), 57.9);
    time.mjd(57.9);
    test_value(time.mjd(), 57.9);
    time.secs(57.9);
    test_value(time.secs(), 57.9);
    time.days(57.9);
    test_value(time.days(), 57.9);

    // Test convert method
    time.secs(t);
    test_value(time.convert(GTimeReference(55197.000766018518519, "days", "TT", "LOCAL")),
               t/86400.0);
    test_value(time.convert(GTimeReference(0.0, "s", "TT", "LOCAL")),
               t + mjd_ref*86400.0, 1.0e-6); //!< Poor precision on OpenSolaris

    // Test set method
    time.set(12.3, GTimeReference(55197.000766018518519, "days", "TT", "LOCAL"));
    test_value(time.days(), 12.3);
    time.set(12.3, GTimeReference(0.0, "secs", "TT", "LOCAL"));
    test_value(time.secs(), 12.3 - mjd_ref*86400.0);

    // Test operators
    GTime a(13.72);
    GTime b(6.28);
    test_value((a+b).secs(), 20.00);
    test_value((a-b).secs(), 7.44);
    test_value((a*3.3).secs(), 45.276);
    test_value((3.3*a).secs(), 45.276);
    test_value((a/13.72).secs(), 1.0);
    test_assert(a == a, "Equality operator corrupt.");
    test_assert(a != b, "Non-equality operator corrupt.");
    test_assert(a > b, "Greater than operator corrupt.");
    test_assert(a >= b, "Greater than or equal operator corrupt.");
    test_assert(b < a, "Less than operator corrupt.");
    test_assert(b <= a, "Less than or equal operator corrupt.");

    // Return
    return;
}
Пример #14
0
int main(int argc, char ** argv) {
    if (argc < 2) {
        std::cout << "ps7a [input file]" << std::endl;
        return -1;
    }

    std::ifstream inputfile(argv[1]);  ///< Opens input file based on argv[1]
    if (!inputfile) {
        std::cout << "Could not open " << argv[1] << std::endl;
        return -1;
    }

    std::ofstream outputfile;  ///< Opens output file based on argv[1] w/ .rpt
    std::string outputfilename = argv[1];
    outputfilename += ".rpt";
    outputfile.open(outputfilename.c_str());
    if (!outputfile) {
        std::cout << "Could not open output file" << std::endl;
        return -1;
    }

    int linenum = 0;   ///< Keeps track of line number in file
    std::string temp;   ///< Stores line to use regex with
    bool test = false;   ///< To help determine if failure or not
    std::string tdatet;   ///< Stores the terminating time
    std::string datet;    ///< Stores the beginning time

    boost::regex expression(".*\\(log\\.c\\.166\\) server started");
    boost::regex expression2("[0-9]{2}:[0-6][0-9]:[0-9]{2}");
    boost::regex expression3
    (".*oejs\\.AbstractConnector:Started SelectChannelConnector");
    boost::smatch fmatch;
    boost::smatch dmatch;
    boost::smatch sumatch;


    /**
     *  This while loop gets a line from the file
     *
     *  It then increases the line count since the linenum starts at
     *  0 but the file starts at line 1
     *
     *  The loop then checks to see if we already found success denoted by test. If
     *  test is true we then check to see if we match the correct terminating command
     *  If the command matches using regex, we than extract the time and subtract it from
     *  The starting time, we set test to false, and we output all this to the file.
     *
     *  If test is true and we find another instance of the server starting, there was a failure
     *
     *  The most important part of this loop tests to see when (log.c.166) is called which
     *  is an instance of the server starting. We record the line number its on, when it starts
     *  and then we move on to our checks by setting test to true.
     *
     */
    while (std::getline(inputfile, temp)) {
        ++linenum;
        if (test) {
            if (boost::regex_search(temp, sumatch, expression3)) {
                outputfile << " success";
                tdatet = sumatch[0];
                if (boost::regex_search(tdatet, dmatch, expression2)) {
                    tdatet = dmatch[0];
                    boost::posix_time::time_duration time2
                    (boost::posix_time::duration_from_string(datet));
                    boost::posix_time::time_duration time1
                    (boost::posix_time::duration_from_string(tdatet));
                    time2 = time1 - time2;
                    std::string time = to_simple_string(time2);
                    outputfile << " " << time << std::endl;
                }
                test = false;
            } else {
                if (boost::regex_search(temp, fmatch, expression)) {
                    outputfile << " failure" << std::endl;
                    test = false;
                }
            }
        } else {
            if (boost::regex_search(temp, fmatch, expression)) {
                datet = fmatch[0];
                if (boost::regex_search(datet, dmatch, expression2)) {
                    outputfile << linenum << " " << datet;
                    datet = dmatch[0];
                    test = true;
                }
            }
        }
    }

    /**
     * 
     *  If for some reason we reach the end of the file and the server was never
     *  properly shutdown, we get a success as it will do that automatically.
     *
     */
    if (test) {
        outputfile << " success" << std::endl;
    }

    outputfile.close();
    inputfile.close();

    return 0;
}
Пример #15
0
void KNDdeTorusCollocation::init(const KNVector& sol, const KNVector& par)
{
  double* t1 = new double[NTAU+1];
  double* t2 = new double[NTAU+1];
  for (size_t i2 = 0; i2 < nint2; i2++)
  {
    for (size_t i1 = 0; i1 < nint1; i1++)
    {
      for (size_t j2 = 0; j2 < ndeg2; j2++)
      {
        for (size_t j1 = 0; j1 < ndeg1; j1++)
        {
          const size_t idx = idxmap(j1, j2, i1, i2); // this is a unique

          time1(idx) = ((double)i1 + col1(j1)) / nint1;
          time2(idx) = ((double)i2 + col2(j2)) / nint2;
        }
      }
    }
  }

  sys->p_tau(p_tau, time1, par);

  p_xx.clear();
  for (size_t idx = 0; idx < time1.size(); ++idx)
  {
    t1[0] = time1(idx);
    t2[0] = time2(idx);
    for (size_t k = 0; k < NTAU; k++)
    {
      t1[1+k] = (t1[0] - p_tau(k,idx) / par(0)) - floor(t1[0] - p_tau(k,idx) / par(0));
      t2[1+k] = (t2[0] - par(RHO) * p_tau(k,idx) / par(0)) - floor(t2[0] - par(RHO) * p_tau(k,idx) / par(0));
    }

    for (size_t k = 0; k < NTAU + 1; k++)
    {
      size_t i1 = static_cast<size_t>(floor(nint1 * t1[k]));
      size_t i2 = static_cast<size_t>(floor(nint2 * t2[k]));
      // some error checking
      if ((t1[k] > 1.0) || (t2[k] > 1.0) ||
          (t1[k] < 0.0) || (t2[k] < 0.0)) std::cout << "Er ";
      if ((i1 >= nint1) || (i2 >= nint2)) std::cout << "Ei ";
      // end error checking
      for (size_t j2 = 0; j2 < ndeg2 + 1; j2++)
      {
        for (size_t j1 = 0; j1 < ndeg1 + 1; j1++)
        {
          const size_t idxKK = idxkk(j1, j2, k);
          kk(idxKK,idx) = idxmap(j1, j2, i1, i2);
          ee(idxKK,idx) = idxKK;
        }
      }
    }

    // sorting
    comp aa(kk.pointer(0,idx));
    std::sort(ee.pointer(0,idx), ee.pointer(0,idx) + (NTAU + 1)*(ndeg1 + 1)*(ndeg2 + 1), aa);

    // filtering same indices
    rr(ee(0,idx),idx) = 0;
    size_t nz = 0;
    for (size_t i = 1; i < (NTAU + 1)*(ndeg1 + 1)*(ndeg2 + 1); i++)
    {
      if (kk(ee(i-1,idx),idx) != kk(ee(i,idx),idx)) nz++;
      rr(ee(i,idx),idx) = nz;
    }

    // interpolate the solution
    for (size_t k = 1; k < NTAU + 1; k++)
    {
      const double c1 = nint1 * t1[k] - floor(nint1 * t1[k]);
      const double c2 = nint2 * t2[k] - floor(nint2 * t2[k]);
      for (size_t j2 = 0; j2 < ndeg2 + 1; j2++)
      {
        for (size_t j1 = 0; j1 < ndeg1 + 1; j1++)
        {
          const size_t idxKK = idxkk(j1, j2, k);
          const double cf = poly_lgr_eval(mesh1, j1, c1) * poly_lgr_eval(mesh2, j2, c2);
          for (size_t p = 0; p < NDIM; p++)
          {
            p_xx(p, k - 1, idx) += cf * sol(p + NDIM * kk(idxKK, idx));
          }
        }
      }
    }
    // derivatives at all delays
    for (size_t k = 0; k < NTAU + 1; k++)
    {
      const double c1 = nint1 * t1[k] - floor(nint1 * t1[k]);
      const double c2 = nint2 * t2[k] - floor(nint2 * t2[k]);
      for (size_t j2 = 0; j2 < ndeg2 + 1; j2++)
      {
        for (size_t j1 = 0; j1 < ndeg1 + 1; j1++)
        {
          const size_t idxKK = idxkk(j1, j2, k);
          const double cf1 = poly_dlg_eval(mesh1, j1, c1) * nint1 * poly_lgr_eval(mesh2, j2, c2);
          const double cf2 = poly_lgr_eval(mesh1, j1, c1) * poly_dlg_eval(mesh2, j2, c2) * nint2;
          for (size_t p = 0; p < NDIM; p++)
          {
            p_xx(p, NTAU + 2*k, idx)   += cf1 * sol(p + NDIM * kk(idxKK, idx));
            p_xx(p, NTAU + 2*k + 1, idx) += cf2 * sol(p + NDIM * kk(idxKK, idx));
          }
        }
      }
    }
  }
//   for (int idx = 0; idx < time1.size(); ++idx) std::cout<<p_xx(0, NTAU, idx)<<"\t";
//   std::cout<<"\np_xx(0,...) was\n";
  delete[] t2;
  delete[] t1;
}
Пример #16
0
void CCalOOMTest::CreateEntriesL()
	{
	_LIT8(KGuid1, "Reminder-1");
	_LIT8(KGuid2, "Appt-1");
		
	_LIT(KEntryStartTime, 		"20121119:013000.000000"); // 20-12-2012 01.30
	_LIT(KEntryEndTime, 		"20121119:090000.000000"); // 20-12-2012 09.00
	
	_LIT(KTimeUntil, 			"20131119:013000.000000"); // 20-12-2013 01.30
	
	_LIT(KSummary1, "THIS SUMMARY");
	_LIT(KSummary2, "Appt summary");
	
	
	//entry 1	
	HBufC8* guid8 = HBufC8::NewL(KGuid1().Length());
	guid8->Des().Copy(KGuid1);
	CleanupStack::PushL(guid8);
	CCalEntry* entry = CCalEntry::NewL(CCalEntry::EReminder, guid8, CCalEntry::EMethodAdd, (TUint)0);	
	CleanupStack::Pop(guid8);
	entry->SetSummaryL(KSummary1);
	
	// entry2
	guid8 = HBufC8::NewL(KGuid2().Length());
	guid8->Des().Copy(KGuid2);
	CleanupStack::PushL(guid8);
	CCalEntry* entry2 = CCalEntry::NewL(CCalEntry::EAppt, guid8, CCalEntry::EMethodAdd, (TUint)0);	
	CleanupStack::Pop(guid8);
	entry2->SetSummaryL(KSummary2);
	
	TTime time1(KEntryStartTime());
	TTime time2(KEntryEndTime());
	TCalTime st;
	st.SetTimeUtcL(time1);
	TCalTime end;
	end.SetTimeUtcL(time2);
		
	entry->SetStartAndEndTimeL(st, end); 
	entry2->SetStartAndEndTimeL(st, end);
	
	TCalRRule* rRule=new (ELeave) TCalRRule(TCalRRule::EDaily);
	TCalTime calTime = entry->StartTimeL();
	rRule->SetDtStart(calTime);
	rRule->SetInterval(1);
	TTime until(KTimeUntil());
	TCalTime untilTime;
	untilTime.SetTimeUtcL(until);
	rRule->SetUntil(untilTime); 
	
	entry->SetRRuleL(*rRule);
	entry2->SetRRuleL(*rRule);
	
	TInt						entriesStored(0);
	RPointerArray<CCalEntry>	entriesToStore;
	CleanupResetAndDestroyPushL(entriesToStore);
	entriesToStore.AppendL(entry);
	entriesToStore.AppendL(entry2);
	iTestLib->SynCGetEntryViewL().StoreL(entriesToStore, entriesStored);

	delete rRule;
	CleanupStack::PopAndDestroy(&entriesToStore);
	
	// Find
	_LIT(KFindSt, 		"20131117:013000.000000"); // The event "overlaps" with this search range, hence must be caught. The reminder must not be caught (its end time = start time).
	_LIT(KFindEnd, 		"20131119:093000.000000");

	CalCommon::TCalViewFilter filter = CalCommon::EIncludeAll;
	TestFindInstancesL(KFindSt, KFindEnd, filter); // calling OOM test function
	}
Пример #17
0
int main(int argc, char *argv[]) {
    if (argc >= 4) {
        unsigned int n, p, k, tam_grupo, resto, inicio;
        unsigned long thread_activo;
        unsigned long seed = mix(clock(), time(NULL), getpid());
        time_586 start, stop;

        /* Argumentos del programa.
         * n = cantidad de usuarios.
         * k = cantidad de adversarios
         * p = cantidad de threads
         */
        n = atoi(argv[1]);
        k = atoi(argv[2]);
        p = atoi(argv[3]);

        pthread_t threads[p];
        init_thread_pool(p);
        pthread_attr_t attr;

        pthread_mutex_init(&mutex_thread_pool, NULL);
        pthread_mutex_init(&mutex_grupos, NULL);
        pthread_mutex_init(&mutex_identificados, NULL);
        pthread_mutex_init(&mutex_claves, NULL);
        pthread_attr_init(&attr);
        pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);

        /* Bitset para almacenar usuarios, n bits */
        mpz_init2(usuarios, n);

        srand(seed);
        time2(start);

        /* Inicialmente creamos k grupos */
        tam_grupo = floor(n / k);
        resto = n % k;
        inicio = 0;
        if (resto > 0) {
            /* Creamos 'k-resto' grupos de tamaño tam_grupo */
            for (unsigned int i = 0; i < k-resto; i++) {
                grupos.push(std::make_pair(inicio, inicio + tam_grupo - 1));
                inicio += tam_grupo;
            }
            /* Creamos 'resto' grupos de tamaño tam_grupo+1 */
            for (unsigned int i = 0; i < resto; i++) {
                grupos.push(std::make_pair(inicio, inicio + tam_grupo));
                inicio += tam_grupo+1;
            }
        } else {
            /* Si la división es exacta, simplemente creamos 'k' grupos
             * de tamaño tam_grupo */
            for (unsigned int i = 0; i < k; i++) {
                grupos.push(std::make_pair(inicio, inicio + tam_grupo - 1));
                inicio += tam_grupo;
            }
        }
        asignar_adversarios(usuarios, n, k);

        /* En un comienzo hay k claves distribuidas (una para cada grupo) */
        claves = k;

        /* Iteramos mientras no hayamos identificado todos los adversarios */
        pthread_mutex_lock(&mutex_identificados);
        while (identificados < k) {
            pthread_mutex_unlock(&mutex_identificados);

            pthread_mutex_lock(&mutex_grupos);
            /* En este instante de tiempo puede que no haya grupos pendientes
             * por procesar, lo que no significa, necesariamente, que todos los
             * adversarios fueron identificados. De ser así, se va a seguir
             * iterando hasta que se agregue un nuevo grupo a procesar a la queue.
             */
            while (grupos.size() > 0) {
                pthread_mutex_unlock(&mutex_grupos);

                pthread_mutex_lock(&mutex_thread_pool);
                //std::cout << "thread_pool: " << thread_pool.size() << std::endl;
                /* Si bien puede haber grupos pendientes por procesar, puede
                 * ocurrir que en este instante de tiempo todos los threads
                 * estén ocupados. De ser así, se sigue iterando hasta que un
                 * thread se desocupe.
                 */
                if (thread_pool.size() > 0) {
                    /* Se guarda el id del primer thread que está desocupado. */
                    thread_activo = thread_pool.front();
                    thread_pool.pop();
                } else {
                    pthread_mutex_unlock(&mutex_thread_pool);
                    /* Si no hay threads disponibles, se espera hasta que uno lo esté. */
                    while (true) {
                        pthread_mutex_lock(&mutex_thread_pool);
                        if (thread_pool.size() > 0) {
                            /* Se guarda el id del primer thread que está desocupado. */
                            thread_activo = thread_pool.front();
                            thread_pool.pop();
                            break;
                        }
                        pthread_mutex_unlock(&mutex_thread_pool);
                    }
                }
                /* Se envía trabajo al thread desocupado. */
                pthread_create(&threads[thread_activo], &attr, check_groups, (void *) thread_activo);
                pthread_mutex_unlock(&mutex_thread_pool);
                pthread_mutex_lock(&mutex_grupos);
            }
            pthread_mutex_unlock(&mutex_grupos);

            pthread_mutex_lock(&mutex_identificados);
        }
        pthread_mutex_unlock(&mutex_identificados);
        time2(stop);
        while (true) {
            pthread_mutex_lock(&mutex_thread_pool);
            if (thread_pool.size() == p) {
                break;
            }
            pthread_mutex_unlock(&mutex_thread_pool);
        }
        mpz_clear(usuarios);
        /* Output: claves encontradas y tiempo de ejecución */
        printf("%d %d %.20fs\n", k, claves, time_diff(stop, start) / 1000000.0);
    } else {
        usage(argv);
    }
    pthread_mutex_destroy(&mutex_thread_pool);
    pthread_mutex_destroy(&mutex_grupos);
    pthread_mutex_destroy(&mutex_identificados);
    pthread_mutex_destroy(&mutex_claves);
    pthread_exit(EXIT_SUCCESS);
}
Пример #18
0
    void posts()
    {
        QDateTime time1(QDate(2013, 1, 2), QTime(12, 34, 56));
        QDateTime time2(QDate(2012, 3, 4), QTime(10, 11, 12));

        const QString id1 = QLatin1String("id1");
        const QString id2 = QLatin1String("id2");
        const QString id3 = QLatin1String("id3");

        const QString name1 = QLatin1String("name1");
        const QString name2 = QLatin1String("name2");
        const QString name3 = QLatin1String("name3");

        const QString body1 = QLatin1String("body1");
        const QString body2 = QLatin1String("body2");
        const QString body3 = QLatin1String("body3");

        const QString icon1 = QLatin1String("/icon.jpg");
        const QString image1 = QLatin1String("http://example.com/image1.jpg");
        const QString image2 = QLatin1String("http://example.com/image2.jpg");
        const QString image3 = QLatin1String("http://example.com/image3.jpg");
        const QString screen1 = QLatin1String("screen1");
        const QString retweeter1 = QLatin1String("retweeter1");
        const QString key1 = QLatin1String("key1");
        const QString secret1 = QLatin1String("secret1");

        TwitterPostsDatabase database;

        database.addTwitterPost(
                    id1, name1, body1, time1, icon1,
                    QList<QPair<QString, SocialPostImage::ImageType> >()
                            << qMakePair(image1, SocialPostImage::Photo)
                            << qMakePair(image2, SocialPostImage::Video),
                    screen1, retweeter1, key1, secret1, 1);
        database.addTwitterPost(
                    id1, name1, body1, time1, icon1,
                    QList<QPair<QString, SocialPostImage::ImageType> >()
                            << qMakePair(image1, SocialPostImage::Photo)
                            << qMakePair(image2, SocialPostImage::Video),
                    screen1, retweeter1, key1, secret1, 2);
        database.addTwitterPost(
                    id2, name2, body2, time2, icon1,
                    QList<QPair<QString, SocialPostImage::ImageType> >()
                            << qMakePair(image3, SocialPostImage::Photo),
                    screen1, retweeter1, key1, secret1, 1);
        database.addTwitterPost(
                    id3, name3, body3, time2, icon1,
                    QList<QPair<QString, SocialPostImage::ImageType> >(),
                    screen1, retweeter1, key1, secret1, 2);

        database.commit();
        database.wait();
        QCOMPARE(database.writeStatus(), AbstractSocialCacheDatabase::Finished);

        database.refresh();
        database.wait();
        QCOMPARE(database.readStatus(), AbstractSocialCacheDatabase::Finished);

        QList<SocialPost::ConstPtr> posts;

        posts = database.posts();
        QCOMPARE(posts.count(), 3);

        SocialPost::ConstPtr post;
        do {
            post = posts.takeFirst();
        } while (post->identifier() != id1 && posts.count() > 0);

        QCOMPARE(post->identifier(), id1);
        QCOMPARE(post->name(), name1);
        QCOMPARE(post->body(), body1);
        QCOMPARE(post->timestamp(), time1);
        QCOMPARE(post->icon(), icon1);
        QCOMPARE(post->images().count(), 2);
        QCOMPARE(TwitterPostsDatabase::screenName(post), screen1);
        QCOMPARE(TwitterPostsDatabase::retweeter(post), retweeter1);
        QCOMPARE(TwitterPostsDatabase::consumerKey(post), key1);
        QCOMPARE(TwitterPostsDatabase::consumerSecret(post), secret1);
        QCOMPARE(post->accounts().count(), 2);

        database.removePosts(2);
        database.commit();
        database.refresh();
        database.wait();
        QCOMPARE(database.writeStatus(), AbstractSocialCacheDatabase::Finished);
        QCOMPARE(database.readStatus(), AbstractSocialCacheDatabase::Finished);

        posts = database.posts();
        QCOMPARE(posts.count(), 2);

        database.removePosts(1);
        database.commit();
        database.refresh();
        database.wait();
        QCOMPARE(database.writeStatus(), AbstractSocialCacheDatabase::Finished);
        QCOMPARE(database.readStatus(), AbstractSocialCacheDatabase::Finished);

        posts = database.posts();
        QCOMPARE(posts.count(), 0);
    }
Пример #19
0
    void notifications()
    {
        QDateTime time1(QDate(2013, 1, 2), QTime(12, 34, 56));
        QDateTime time2(QDate(2012, 3, 4), QTime(10, 11, 12));
        QDateTime time3(QDate(2014, 1, 2), QTime(12, 34, 56));

        const QString id1 = QLatin1String("id1");
        const QString id2 = QLatin1String("id2");
        const QString id3 = QLatin1String("id3");

        const QString from1 = QLatin1String("from1");
        const QString from2 = QLatin1String("from2");
        const QString from3 = QLatin1String("from3");

        const QString to1 = QLatin1String("to1");
        const QString to2 = QLatin1String("to2");
        const QString to3 = QLatin1String("to3");

        const QString title1 = QLatin1String("title1");
        const QString title2 = QLatin1String("title2");
        const QString title3 = QLatin1String("title3");
        
        const QString link1 = QLatin1String("link1");
        const QString link2 = QLatin1String("link2");
        const QString link3 = QLatin1String("link3");

        const QString app1 = QLatin1String("app1");
        const QString app2 = QLatin1String("app2");
        const QString app3 = QLatin1String("app3");

        const QString object1 = QLatin1String("object1");
        const QString object2 = QLatin1String("object2");
        const QString object3 = QLatin1String("object3");

        const bool unread1 = true;
        const bool unread2 = false;
        const bool unread3 = false;

        int account1 = 1; 
        int account2 = 2; 

        QString clientId = QLatin1String("clientId");

        FacebookNotificationsDatabase database;

        database.addFacebookNotification(id1, from1, to1, time1, time1,
                                         title1, link1, app1, object1, unread1, account1, clientId);

        database.addFacebookNotification(id2, from2, to2, time2, time2,
                                         title2, link2, app2, object2, unread2, account1, clientId);

        database.addFacebookNotification(id3, from3, to3, time3, time3,
                                         title3, link3, app3, object3, unread3, account2, clientId);
        database.sync();
        database.wait();
        QCOMPARE(database.writeStatus(), AbstractSocialCacheDatabase::Finished);

        QList<FacebookNotification::ConstPtr> notifications;

        notifications = database.notifications();
        QCOMPARE(notifications.count(), 3);

        FacebookNotification::ConstPtr notification;
        do {
            notification = notifications.takeFirst();
        } while (notification->facebookId() != id1 && notifications.count() > 0);

        QCOMPARE(notification->facebookId(), id1);
        QCOMPARE(notification->from(), from1);
        QCOMPARE(notification->to(), to1);
        QCOMPARE(notification->createdTime(), time1);
        QCOMPARE(notification->updatedTime(), time1);
        QCOMPARE(notification->title(), title1);
        QCOMPARE(notification->link(), link1);
        QCOMPARE(notification->application(), app1);
        QCOMPARE(notification->object(), object1);
        QCOMPARE(notification->unread(), unread1);
        QCOMPARE(notification->accountId(), account1);
        QCOMPARE(notification->clientId(), clientId);

        QStringList toBeDeleted;
        toBeDeleted.append(id1);
        toBeDeleted.append(id2);
        database.removeNotifications(toBeDeleted);
        database.sync();
        database.wait();
        QCOMPARE(database.writeStatus(), AbstractSocialCacheDatabase::Finished);

        notifications = database.notifications();
        QCOMPARE(notifications.count(), 1);

        notification = notifications.takeFirst();
        QCOMPARE(notification->facebookId(), id3);
        QCOMPARE(notification->from(), from3);
        QCOMPARE(notification->to(), to3);
        QCOMPARE(notification->createdTime(), time3);
        QCOMPARE(notification->updatedTime(), time3);
        QCOMPARE(notification->title(), title3);
        QCOMPARE(notification->link(), link3);
        QCOMPARE(notification->application(), app3);
        QCOMPARE(notification->object(), object3);
        QCOMPARE(notification->unread(), unread3);
        QCOMPARE(notification->accountId(), account2);
        QCOMPARE(notification->clientId(), clientId);

        database.removeNotification(id3);
        database.sync();
        database.wait();
        QCOMPARE(database.writeStatus(), AbstractSocialCacheDatabase::Finished);
        
        notifications = database.notifications();
        QCOMPARE(notifications.count(), 0);

        database.addFacebookNotification(id1, from1, to1, time1, time1,
                                         title1, link1, app1, object1, unread1, account1, clientId);

        database.addFacebookNotification(id2, from2, to2, time2, time2,
                                         title2, link2, app2, object2, unread2, account1, clientId);

        database.addFacebookNotification(id3, from3, to3, time3, time3,
                                         title3, link3, app3, object3, unread3, account2, clientId);
        database.sync();
        database.wait();
        QCOMPARE(database.writeStatus(), AbstractSocialCacheDatabase::Finished);

        notifications = database.notifications();
        QCOMPARE(notifications.count(), 3);

        database.removeNotifications(account1);
        database.sync();
        database.wait();
        QCOMPARE(database.writeStatus(), AbstractSocialCacheDatabase::Finished);

        notifications = database.notifications();
        QCOMPARE(notifications.count(), 1);

        database.removeNotifications(account2);
        database.sync();
        database.wait();
        QCOMPARE(database.writeStatus(), AbstractSocialCacheDatabase::Finished);

        notifications = database.notifications();
        QCOMPARE(notifications.count(), 0);
          
        database.addFacebookNotification(id1, from1, to1, time1, time1,
                                         title1, link1, app1, object1, unread1, account1, clientId);
        database.removeNotification(id1);
        database.sync();
        database.wait();
        QCOMPARE(database.writeStatus(), AbstractSocialCacheDatabase::Finished);

        notifications = database.notifications();
        QCOMPARE(notifications.count(), 0);
    }
Пример #20
0
void DateTimeTextMatchPlugin::doGetPossibleMatches( const QString& text )
{
    //
    // check for years (numbers between 1900 and 2020 for example)
    // check for stuff like "June 22" or even "June 22-26th" (the latter can be used as start and end time already)
    // check for "2 o'clock"
    // check for "14:23"
    // check for 12.6.2009 and 6/12/2009 and 6/12/09 and 6.12.09
    //

    m_years.clear();
    m_dates.clear();
    m_times.clear();
    m_dateRanges.clear();
    m_text = text;

    // we are english-only here!
    QStringList longMonthNames;
    QStringList shortMonthNames;
    for ( int i = 1; i <= 12; ++i ) {
        longMonthNames << m_enLocale.monthName( i, QLocale::LongFormat );
        shortMonthNames << m_enLocale.monthName( i, QLocale::ShortFormat );
    }

    //
    // most of the dates and times can be checked with QRegExp
    //

    // DD.MM.YYYY
    QRegExp date1( "\\b\\d{1,2}\\.\\d{1,2}\\.\\d{4,4}\\b" );

    // DD.MM.YY
    QRegExp date2( "\\b\\d{1,2}\\.\\d{1,2}\\.\\d{2,2}\\b" );

    // MM/DD/YYYY
    QRegExp date3( "\\b\\d{1,2}/\\d{1,2}/\\d{4,4}\\b" );

    // MM/DD/YY
    QRegExp date4( "\\b\\d{1,2}/\\d{1,2}/\\d{2,2}\\b" );

    // January MM [YYYY] (no word boundry at the end for 'st' or 'nd' or 'th') (also excluding ranges)
    QRegExp date5( QString( "\\b(%1)\\s\\d{1,2}(?!(\\d|\\s?-\\s?\\d))(\\s\\d{4,4})?" ).arg( longMonthNames.join( "|" ) ) );

    // January, MM [YYYY] (no word boundry at the end for 'st' or 'nd' or 'th') (also excluding ranges)
    QRegExp date6( QString( "\\b(%1),\\s?\\d{1,2}(?!(\\d|\\s?-\\s?\\d))(\\s\\d{4,4})?" ).arg( longMonthNames.join( "|" ) ) );

    // FIXME: date ranges 1-4

    QRegExp dateRange5( QString( "(\\b(?:%1)\\s\\d{1,2})\\s?-\\s?(\\d{1,2})(\\s\\d{4,4})?" ).arg( longMonthNames.join( "|" ) ) );

    QRegExp dateRange6( QString( "(\\b(?:%1),\\s?\\d{1,2})\\s?-\\s?(\\d{1,2})(\\s\\d{4,4})?" ).arg( longMonthNames.join( "|" ) ) );

    // YYYY (exclude those in full dates matched by the above)
    QRegExp year( "[^\\./]\\d{4,4}\\b" );

    // hh:mm[pm|am]
    QRegExp time1( "\\b\\d{1,2}\\:\\d{2,2}\\s?(pm|am|AM|PM)?\\b" );

    // hh:mm
    QRegExp time2( "\\b\\d{1,2}\\:\\d{2,2}\\b(?!\\s?(pm|am|AM|PM))\\b" );

    // hh o'clock
//    QRegExp time3( "\\b\\d{1,2}\\so'clock\\b" );

    lookForYears( year );

    lookForDates( date1, "d.M.yyyy" );
    lookForDates( date2, "d.M.yy" );
    lookForDates( date3, "M/d/yyyy" );
    lookForDates( date4, "M/d/yy" );
    lookForDates( date5, "MMMM d", true );
    lookForDates( date5, "MMMM d yyyy" );
    lookForDates( date6, "MMMM, d", true );
    lookForDates( date6, "MMMM,d", true );
    lookForDates( date6, "MMMM, d yyyy" );
    lookForDates( date6, "MMMM,d yyyy" );

    lookForDateRanges( dateRange5, "MMMM d", 1, 2, 3, true );
    lookForDateRanges( dateRange5, "MMMM d yyyy", 1, 2, 3, false );
    lookForDateRanges( dateRange6, "MMMM,d", 1, 2, 3, true );
    lookForDateRanges( dateRange6, "MMMM, d", 1, 2, 3, true );
    lookForDateRanges( dateRange6, "MMMM,d yyyy", 1, 2, 3, false );
    lookForDateRanges( dateRange6, "MMMM, d yyyy", 1, 2, 3, false );

    lookForTimes( time1, "h:map" );
    lookForTimes( time1, "h:m ap" );
    lookForTimes( time2, "h:m" );

    // FIXME: do a date and time proximity search to create combined datetime objects

    //
    // Now use the dates and times to create statements
    //
    for ( QHash<int, QPair<QDate, int> >::const_iterator it = m_dates.constBegin();
          it != m_dates.constEnd(); ++it ) {
        // FIXME: this is not great: 1. dtstart has range dateTime, 2. we do not know that it is a start
        //        better use something else or even create Scribo::Literal as alternative to Entity
        Scribo::Statement s( Nepomuk::Vocabulary::PIMO::dtstart(), Nepomuk::Variant( it.value().first ), Soprano::Graph() );
        Scribo::TextOccurrence oc;
        oc.setStartPos( it.key() );
        oc.setLength( it.value().second );
//        oc.setRelevance( 0.9 ); ?????????
        s.addOccurrence( oc );
        addNewMatch( s );
    }

    for ( QHash<int, QPair<QTime, int> >::const_iterator it = m_times.constBegin();
          it != m_times.constEnd(); ++it ) {
        // FIXME: this is not great: 1. dtstart has range dateTime, 2. we do not know that it is a start
        //        better use something else or even create Scribo::Literal as alternative to Entity
        Scribo::Statement s( Nepomuk::Vocabulary::PIMO::dtstart(), Nepomuk::Variant( it.value().first ), Soprano::Graph() );
        Scribo::TextOccurrence oc;
        oc.setStartPos( it.key() );
        oc.setLength( it.value().second );
//        oc.setRelevance( 0.9 ); ?????????
        s.addOccurrence( oc );
        addNewMatch( s );
    }

    for ( QHash<int, QPair<QPair<QDate, QDate>, int> >::const_iterator it = m_dateRanges.constBegin();
          it != m_dateRanges.constEnd(); ++it ) {
        // FIXME: this is not great: 1. dtstart has range dateTime, 2. we do not know that it is a start
        //        better use something else or even create Scribo::Literal as alternative to Entity
        Scribo::Statement s1( Nepomuk::Vocabulary::PIMO::dtstart(), Nepomuk::Variant( it.value().first.first ), Soprano::Graph() );
        Scribo::TextOccurrence oc1;
        oc1.setStartPos( it.key() );
        oc1.setLength( it.value().second );
//        oc.setRelevance( 0.9 ); ?????????
        s1.addOccurrence( oc1 );
        addNewMatch( s1 );

        Scribo::Statement s2( Nepomuk::Vocabulary::PIMO::dtend(), Nepomuk::Variant( it.value().first.second ), Soprano::Graph() );
        Scribo::TextOccurrence oc2;
        oc2.setStartPos( it.key() );
        oc2.setLength( it.value().second );
//        oc.setRelevance( 0.9 ); ?????????
        s2.addOccurrence( oc2 );
        addNewMatch( s2 );
    }

    emitFinished();
}
Пример #21
0
    void posts()
    {
        QDateTime time1(QDate(2013, 1, 2), QTime(12, 34, 56));
        QDateTime time2(QDate(2012, 3, 4), QTime(10, 11, 12));

        const QString id1 = QLatin1String("id1");
        const QString id2 = QLatin1String("id2");
        const QString id3 = QLatin1String("id3");

        const QString name1 = QLatin1String("name1");
        const QString name2 = QLatin1String("name2");
        const QString name3 = QLatin1String("name3");

        const QString body1 = QLatin1String("body1");
        const QString body2 = QLatin1String("body2");
        const QString body3 = QLatin1String("body3");

        const QString icon1 = QLatin1String("/icon.jpg");
        const QString image1 = QLatin1String("http://example.com/image1.jpg");
        const QString image2 = QLatin1String("http://example.com/image2.jpg");
        const QString image3 = QLatin1String("http://example.com/image3.jpg");
        const QString attachment1 = QLatin1String("attachment1");
        const QString caption1 = QLatin1String("caption1");
        const QString description1 = QLatin1String("description1");
        const QString url1 = QLatin1String("http://example.com/attachment.png");
        const QString client1 = QLatin1String("client1");

        FacebookPostsDatabase database;

        database.addFacebookPost(
                    id1, name1, body1, time1, icon1,
                    QList<QPair<QString, SocialPostImage::ImageType> >()
                            << qMakePair(image1, SocialPostImage::Photo)
                            << qMakePair(image2, SocialPostImage::Video),
                    attachment1, caption1, description1, url1,
                    true, true, client1, 1);
        database.addFacebookPost(
                    id1, name1, body1, time1, icon1,
                    QList<QPair<QString, SocialPostImage::ImageType> >()
                            << qMakePair(image1, SocialPostImage::Photo)
                            << qMakePair(image2, SocialPostImage::Video),
                    attachment1, caption1, description1, url1,
                    true, true, client1, 2);
        database.addFacebookPost(
                    id2, name2, body2, time2, icon1,
                    QList<QPair<QString, SocialPostImage::ImageType> >()
                            << qMakePair(image3, SocialPostImage::Photo),
                    QString(), QString(), QString(), QString(),
                    false, false, client1, 1);
        database.addFacebookPost(
                    id3, name3, body3, time2, icon1,
                    QList<QPair<QString, SocialPostImage::ImageType> >(),
                    QString(), QString(), QString(), QString(),
                    true, true, client1, 2);

        database.commit();
        database.wait();
        QCOMPARE(database.writeStatus(), AbstractSocialCacheDatabase::Finished);

        database.refresh();
        database.wait();
        QCOMPARE(database.readStatus(), AbstractSocialCacheDatabase::Finished);

        QList<SocialPost::ConstPtr> posts;

        posts = database.posts();
        QCOMPARE(posts.count(), 3);

        SocialPost::ConstPtr post;
        do {
            post = posts.takeFirst();
        } while (post->identifier() != id1 && posts.count() > 0);

        QCOMPARE(post->identifier(), id1);
        QCOMPARE(post->name(), name1);
        QCOMPARE(post->body(), body1);
        QCOMPARE(post->timestamp(), time1);
        QCOMPARE(post->icon(), icon1);
        QCOMPARE(post->images().count(), 2);
        QCOMPARE(FacebookPostsDatabase::attachmentName(post), attachment1);
        QCOMPARE(FacebookPostsDatabase::attachmentCaption(post), caption1);
        QCOMPARE(FacebookPostsDatabase::attachmentDescription(post), description1);
        QCOMPARE(FacebookPostsDatabase::attachmentUrl(post), url1);
        QCOMPARE(FacebookPostsDatabase::allowLike(post), true);
        QCOMPARE(FacebookPostsDatabase::allowComment(post), true);
        QCOMPARE(FacebookPostsDatabase::clientId(post), client1);
        QCOMPARE(post->accounts().count(), 2);

        database.removePosts(2);
        database.commit();
        database.refresh();
        database.wait();
        QCOMPARE(database.writeStatus(), AbstractSocialCacheDatabase::Finished);
        QCOMPARE(database.readStatus(), AbstractSocialCacheDatabase::Finished);

        posts = database.posts();
        QCOMPARE(posts.count(), 2);

        database.removePosts(1);
        database.commit();
        database.refresh();
        database.wait();
        QCOMPARE(database.writeStatus(), AbstractSocialCacheDatabase::Finished);
        QCOMPARE(database.readStatus(), AbstractSocialCacheDatabase::Finished);

        posts = database.posts();
        QCOMPARE(posts.count(), 0);
    }
Пример #22
0
static time_t
time1(struct tm * const tmp,
      struct tm * (* const funcp)(const time_t *, long, struct tm *),
      const long offset)
{
	time_t			t;
	const struct state *	sp;
	int			samei, otheri;
	int			sameind, otherind;
	int			i;
	int			nseen;
	int			seen[TZ_MAX_TYPES];
	int			types[TZ_MAX_TYPES];
	int			okay;

	if (tmp == NULL) {
		errno = EINVAL;
		return WRONG;
	}
	if (tmp->tm_isdst > 1)
		tmp->tm_isdst = 1;
	t = time2(tmp, funcp, offset, &okay);

	/*
	** PCTS code courtesy Grant Sullivan.
	*/
	if (okay)
		return t;
	if (tmp->tm_isdst < 0)
		tmp->tm_isdst = 0;	/* reset to std and try again */

	/*
	** We're supposed to assume that somebody took a time of one type
	** and did some math on it that yielded a "struct tm" that's bad.
	** We try to divine the type they started from and adjust to the
	** type they need.
	*/
	sp = (const struct state *) ((funcp == localsub) ?  lclptr : gmtptr);

	for (i = 0; i < sp->typecnt; ++i)
		seen[i] = FALSE;
	nseen = 0;
	for (i = sp->timecnt - 1; i >= 0; --i)
		if (!seen[sp->types[i]]) {
			seen[sp->types[i]] = TRUE;
			types[nseen++] = sp->types[i];
		}
	for (sameind = 0; sameind < nseen; ++sameind) {
		samei = types[sameind];
		if (sp->ttis[samei].tt_isdst != tmp->tm_isdst)
			continue;
		for (otherind = 0; otherind < nseen; ++otherind) {
			otheri = types[otherind];
			if (sp->ttis[otheri].tt_isdst == tmp->tm_isdst)
				continue;
			tmp->tm_sec += sp->ttis[otheri].tt_gmtoff -
					sp->ttis[samei].tt_gmtoff;
			tmp->tm_isdst = !tmp->tm_isdst;
			t = time2(tmp, funcp, offset, &okay);
			if (okay)
				return t;
			tmp->tm_sec -= sp->ttis[otheri].tt_gmtoff -
					sp->ttis[samei].tt_gmtoff;
			tmp->tm_isdst = !tmp->tm_isdst;
		}
	}
	return WRONG;
}