Exemplo n.º 1
0
void testInsertRecord(bool showPassedTests) 
{

	Record *r1 = new Record(2, 11, "1");
	Record *r2 = new Record(1, 12, "2");
	Record *r3 = new Record(12, 13, "3");

	Record **arr = new Record*[2];
	arr[0] = r1;
	arr[1] = r2;
	HighscoreTable ht = HighscoreTable(arr, 2, 2);

	ht.addRecord(r3);
	ht.sort();

	Record **r = ht.getRecords();
	if (recordEqual(r3, r[0]) == false) {
		fmsg("testInsertRecord, records not sorted, r3 isn't first");
	} else if (recordEqual(r2, r[1]) == false) {
		fmsg("testInsertRecord, records not sorted, r2 isn't second");
	} else if (recordEqual(r1, r[2]) == false) {
		fmsg("testInsertRecord, records not sorted, r1 isn't last");
	} else {
		pmsg("testInsertRecord");
	}
}
Exemplo n.º 2
0
void testRecordWithSpaces(bool showPassedTests)
{
	/* write the record */
	FILE *f = fopen("highscore-test.txt", "w+b");
	Record r = Record(123, (long) 123456, "name and number");
	r.writeRecord(f);
	fclose(f);

	/* read the record */
	FILE *g = fopen("highscore-test.txt", "rb");
	char *line = NULL;
	size_t linecap = 0;
	getline(&line, &linecap, g);
	fclose(g);

	/* parse the record */
	Record r2 = Record(string(line));

	if (r2.getScore() != r.getScore() || 
			r2.getTimestamp() != r.getTimestamp() || 
			strcmp(r2.getName().c_str(), r.getName().c_str()) != 0) {
		fmsg("testRecordWithSpaces, records differ");
	} else {
		pmsg("testRecord");
	}

	free(line);
}
Exemplo n.º 3
0
void testMetadata(bool showPassedTests)
{
	/* write to file */
	FILE *f = fopen("highscore-test.txt", "w+b");
	HighscoreMetadata *hm = new HighscoreMetadata(3);
	hm->writeMetadata(f);
	fclose(f);
	delete hm;

	/* read from file  */
	FILE *g = fopen("highscore-test.txt", "rb");
	char *line = NULL;
	size_t linecap = 0;
	getline(&line, &linecap, g);
	fclose(g);

	/* parse */
	string l = string(line);
	hm = new HighscoreMetadata(l);
	free(line);

	/* check */
	if (hm->count != 3) {
		fmsg("testMetadata, count != 3, is %d", hm->count);
	} else {
		pmsg("testMetadata");
	}

	delete hm;
}
Exemplo n.º 4
0
int WhatsAppProto::onGroupChatEvent(WPARAM wParam, LPARAM lParam)
{
	GCHOOK *gch = (GCHOOK*)lParam;
	if (mir_strcmp(gch->pDest->pszModule, m_szModuleName))
		return 0;

	std::string chat_id(T2Utf(gch->pDest->ptszID));
	WAChatInfo *pInfo = SafeGetChat(chat_id);
	if (pInfo == NULL)
		return 0;

	switch (gch->pDest->iType) {
	case GC_USER_LOGMENU:
		ChatLogMenuHook(pInfo, gch);
		break;

	case GC_USER_NICKLISTMENU:
		NickListMenuHook(pInfo, gch);
		break;

	case GC_USER_MESSAGE:
		if (isOnline()) {
			std::string msg(T2Utf(gch->ptszText));
			
			try {
				int msgId = GetSerial();
				time_t now = time(NULL);
				std::string id = Utilities::intToStr(now) + "-" + Utilities::intToStr(msgId);

				FMessage fmsg(chat_id, true, id);
				fmsg.timestamp = now;
				fmsg.data = msg;
				m_pConnection->sendMessage(&fmsg);

				pInfo->m_unsentMsgs[id] = gch->ptszText;
			}
			CODE_BLOCK_CATCH_ALL
		}
		break;

	case GC_USER_PRIVMESS:
		string jid = string(_T2A(gch->ptszUID)) + "@s.whatsapp.net";
		MCONTACT hContact = ContactIDToHContact(jid);
		if (hContact == 0) {
			hContact = AddToContactList(jid, (char*)_T2A(gch->ptszUID));
			setWord(hContact, "Status", ID_STATUS_ONLINE);

			db_set_b(hContact, "CList", "Hidden", 1);
			setTString(hContact, "Nick", gch->ptszUID);
			db_set_dw(hContact, "Ignore", "Mask1", 0);
		}
		CallService(MS_MSG_SENDMESSAGE, hContact, 0);
		break;
	}

	return 0;
}
Exemplo n.º 5
0
void testRecordEqual(bool showPassedTests) 
{
	Record *r1 = new Record(1, 2, "3");
	Record *r2 = new Record(1, 2, "3");
	if (recordEqual(r1, r2) == false) {
		fmsg("testRecordEqual, r1 != r2");
	} else {
		pmsg("testRecordEqual");
	}
}
Exemplo n.º 6
0
UClass* UAirBlueprintLib::LoadClass(const std::string& name)
{
    FString str(name.c_str());
    UClass *cls = StaticLoadClass(UObject::StaticClass(), nullptr, *str);
    if (cls == nullptr) {
        std::string msg = "Failed to load asset class - " + name;
        FString fmsg(msg.c_str());
        LogMessage(TEXT("Load: "), fmsg, LogDebugLevel::Failure);
        throw std::invalid_argument(msg);
    }
    return cls;
}
Exemplo n.º 7
0
void testHighscoreTable(bool showPassedTests)
{
	/* create an array of records */
	Record **records = new Record*[6];
	records[0] = new Record(1, 11, "1");
	records[1] = new Record(2, 12, "2");
	records[2] = new Record(3, 13, "3");
	records[3] = new Record(4, 14, "4");
	records[4] = new Record(5, 15, "5");
	records[5] = new Record(6, 16, "6");

	HighscoreTable ht = HighscoreTable(records, 6, 6);

	ht.writeHighscoreTable("highscore-test.txt");

	HighscoreTable ht2 = HighscoreTable("highscore-test.txt");

	if (ht.getCount() != ht2.getCount()) {
		fmsg("testHighscoreTable, count not the same");
		fmsg(" is %d, should be %d\n", ht2.getCount(), ht.getCount());
	} 

	/* if all the records are equal, this will be true after the loop */
	bool recordsEqual = true;

	/* compare the records */
	for (int i=0; i<ht.getCount(); i++) {
		if (recordEqual(ht.getRecords()[i], ht2.getRecords()[i]) != true) {
			fmsg("testHighscoreTable, records differ");
			recordsEqual = false;
		}
	}

	if (recordsEqual == true) {
		pmsg("testHighscoreTable");
	}
}
Exemplo n.º 8
0
inline T raise_overflow_error(
           const char* function,
           const char* message,
           const T& val,
           const  ::geofeatures_boost::math::policies::overflow_error< ::geofeatures_boost::math::policies::user_error>&)
{
   std::string fmsg("Error in function ");
#ifndef BOOST_NO_RTTI
   fmsg += (geofeatures_boost::format(function) % geofeatures_boost::math::policies::detail::name_of<T>()).str();
#else
   fmsg += function;
#endif
   int prec = 2 + (geofeatures_boost::math::policies::digits<T, geofeatures_boost::math::policies::policy<> >() * 30103UL) / 100000UL;
   std::string msg = do_format(geofeatures_boost::format(message), geofeatures_boost::io::group(std::setprecision(prec), val));
   return user_overflow_error(fmsg.c_str(), msg.c_str(), std::numeric_limits<T>::infinity());
}
Exemplo n.º 9
0
void testAddRecord(bool showPassedTests)
{
	Record **arr = new Record*[2];
	arr[0] = new Record(1, 11, "1");
	arr[1] = new Record(2, 12, "1");
	
	HighscoreTable ht = HighscoreTable(arr, 2, 2);

	Record *r = new Record(3, 13, "3");

	ht.addRecord(r);
	if (recordEqual(r, ht.getRecords()[2]) != true) {
		fmsg("testAddRecord, records differ");
	} else {
		pmsg("testAddRecord");
	}
}
Exemplo n.º 10
0
uint16 SensorTag_ProcessEvent(uint8 task_id, uint16 events)
{
	VOID	task_id;	// OSAL required parameter that isn't used in this function


	///////////////////////////////////////////////////////////////////////
	// system event handle                                               //
	///////////////////////////////////////////////////////////////////////
	if (events & SYS_EVENT_MSG) {
		uint8	*msg;

		if ((msg = osal_msg_receive(sensorTag_TaskID)) != NULL) {
			sensorTag_ProcessOSALMsg((osal_event_hdr_t *) msg);

			// release the OSAL message
			osal_msg_deallocate(msg);
		}

		// return unprocessed events
		return (events ^ SYS_EVENT_MSG);
	}


	///////////////////////////////////////////////////////////////////////
	// start device event                                                //
	///////////////////////////////////////////////////////////////////////
	if (events & EVT_START_DEVICE) {
		// start the device
		GAPRole_StartDevice(&sensorTag_PeripheralCBs);

		// start bond manager
#if !defined(GAPBONDMGR_NO_SUPPORT)
		GAPBondMgr_Register(&sensorTag_BondMgrCBs);
#endif
		// start peripheral device
		oled_init();
		adxl345_softrst();
//		adxl345_self_calibration();

		steps	     = 0;
		BATCD_PXIFG  = ~(BATCD_BV);
		BATCD_IEN   |=  BATCD_IENBIT;

		osal_start_reload_timer(sensorTag_TaskID, EVT_RTC, PERIOD_RTC);
		pwmgr_state_change(PWMGR_S0, 0);

		fmsg(("\033[40;32m\n[power on]\033[0m\n"));
		return (events ^ EVT_START_DEVICE);
	}


	///////////////////////////////////////////////////////////////////////
	// key long press handle                                             //
	///////////////////////////////////////////////////////////////////////
	if (events & EVT_MODE) {
		if (key1_press) {
			oled_clr_screen();
			if ((opmode & 0xF0) == MODE_NORMAL) {
				opmode        = MODE_WORKOUT | MODE_TIME;
				workout.steps = normal.steps;
				workout.time  = osal_getClock();
				fmsg(("\033[40;32m[workout mode]\033[0m\n"));
			} else {
				opmode        = MODE_NORMAL | MODE_TIME;
				fmsg(("\033[40;32m[normal mode]\033[0m\n"));
			}

			pwmgr_state_change(pwmgr, TIME_OLED_OFF);
		}
		return (events ^ EVT_MODE);
	}

	if (events & EVT_SLEEP) {
		if (key1_press) {
			oled_clr_screen();
			opmode = MODE_SLEEP;
			fmsg(("\033[40;32m[sleep mode]\033[0m\n"));

			pwmgr_state_change(pwmgr, TIME_OLED_OFF);
		}
		return (events ^ EVT_SLEEP);
	}

	if (events & EVT_SYSRST) {
		if (key1_press) {
			fmsg(("\033[40;32m[system reset]\033[0m\n"));
			HAL_SYSTEM_RESET();
//			adxl345_self_calibration();
		}
		return (events ^ EVT_SYSRST);
	}


	///////////////////////////////////////////////////////////////////////
	// display handle                                                    //
	///////////////////////////////////////////////////////////////////////
	if (events & EVT_DISP) {
		if (pwmgr == PWMGR_S1) {
			sensorTag_HandleDisp(opmode, acc);
		} else {
			// display battery only
			sensorTag_BattDisp(batt_get_level());
		}
		if (pwmgr != PWMGR_S6)  {
			osal_start_timerEx(sensorTag_TaskID, EVT_DISP, PERIOD_DISP);
		}
		return (events ^ EVT_DISP);
	}


	///////////////////////////////////////////////////////////////////////
	// g-sensor handle                                                   //
	///////////////////////////////////////////////////////////////////////
	if (events & EVT_GSNINT1) {
		adxl345_exit_sleep();
		pwmgr_state_change(PWMGR_S3, TIME_GSEN_OFF);
		return (events ^ EVT_GSNINT1);
	}

	if (events & EVT_GSNINT2) {
		unsigned char	sampling;
		unsigned char	i;

		sampling = adxl345_chk_fifo();
		for (i=0; i<sampling; i++) {
			adxl345_read(acc);
#if (DEBUG_MESSAGE & MSG_STEPS)
			{
				unsigned long	tmp = algo_step(acc);
				if (normal.steps != tmp) {
					stepmsg(("\033[1;33mstep=%0lu\n\033[0m", tmp));
				}
				normal.steps = tmp;
			}
#else
			normal.steps = algo_step(acc);
#endif
		}

		normal.distance  = calc_distance(normal.steps, pi.stride);
		workout.distance = calc_distance((normal.steps - workout.steps), pi.stride);
		normal.calorie   = calc_calorie(normal.distance, pi.weight);
		workout.calorie  = calc_calorie(workout.distance, pi.weight);
		return (events ^ EVT_GSNINT2);
	}

	if (events & EVT_GSENSOR) {
		adxl345_exit_sleep();
		return (events ^ EVT_GSENSOR);
	}


	///////////////////////////////////////////////////////////////////////
	// RTC handle                                                        //
	///////////////////////////////////////////////////////////////////////
	if (events & EVT_RTC) {
		// performed once per second


		// record data
		if ((pwmgr != PWMGR_S5) && (pwmgr != PWMGR_S6)) {
#if defined(HAL_IMAGE_A) || defined(HAL_IMAGE_B)
			if ((osal_getClock() - mark.time) >= (12UL*60UL)) {
#else
			if ((osal_getClock() - mark.time) >= (12UL)) {
#endif
				if (!hash_is_full()) {
					unsigned short	tmp = normal.steps - mark.steps;

					switch (opmode & 0xF0) {
					case MODE_WORKOUT: tmp |= 0x8000; break;
					case MODE_SLEEP:   tmp |= 0x4000; break;
					}
					hash_put(&tmp);
				}
				mark.time  = osal_getClock();
#if defined(HAL_IMAGE_A) || defined(HAL_IMAGE_B)
				if ((mark.time % (24UL*60UL*60UL)) <= (13UL*60UL)) {
#else
				if ((mark.time % (24UL*60UL*60UL)) <= (13UL)) {
#endif
					dmsg(("reset steps...\n"));
					normal.steps  = 0;
					workout.steps = 0;
					STEPS         = 0;
				}
				mark.steps = normal.steps;
			}
		}

		// power management
		switch (pwmgr) {
		case PWMGR_S0:
			pmsg(("\033[40;35mS0 (power on)\033[0m\n"));
			if (pwmgr_saving_timer()) {
				adxl345_enter_sleep();

				osal_pwrmgr_device(PWRMGR_BATTERY);
				pwmgr_state_change(PWMGR_S4, 0);
			}
			break;

		case PWMGR_S1:
			pmsg(("\033[40;35mS1 (rtc+gsen+ble+oled)\033[0m\n"));
			if (pwmgr_saving_timer()) {
				oled_enter_sleep();
				osal_stop_timerEx(sensorTag_TaskID, EVT_MODE);
				osal_stop_timerEx(sensorTag_TaskID, EVT_SLEEP);
				osal_stop_timerEx(sensorTag_TaskID, EVT_SYSRST);

				pwmgr_state_change(PWMGR_S3, TIME_GSEN_OFF);
			}
			break;

		case PWMGR_S2:
			pmsg(("\033[40;35mS2 (rtc+gsen+ble)\033[0m\n"));
			if (gapProfileState == GAPROLE_WAITING) {
				// enable key interrupt mode
				InitBoard(OB_READY);
				pwmgr_state_change(PWMGR_S3, TIME_GSEN_OFF);
			}
			break;

		case PWMGR_S3:
			pmsg(("\033[40;35mS3 (rtc+gsen)\033[0m\n"));
			if (steps == normal.steps) {
				if (pwmgr_saving_timer()) {
					adxl345_enter_sleep();
					pwmgr_state_change(PWMGR_S4, 0);
				}
			} else {
				steps = normal.steps;
				pwmgr_state_change(pwmgr, TIME_GSEN_OFF);
			}
			break;

		case PWMGR_S4:
			pmsg(("\033[40;35mS4 (rtc)\033[0m\n"));
			dmsg(("$"));
			break;

		default:
		case PWMGR_S5:
			pmsg(("\033[40;35mS5 (shutdown)\033[0m\n"));
			adxl345_shutdown();
			osal_stop_timerEx(sensorTag_TaskID, EVT_RTC);
			break;

		case PWMGR_S6:
			pmsg(("\033[40;35mS6 (rtc+oled)\033[0m\n"));
			if (pwmgr_saving_timer()) {
				oled_enter_sleep();

				// enable key interrupt mode
				InitBoard(OB_READY);
				pwmgr_state_change(PWMGR_S5, 0);
			}
			break;
		}

		// battery measure
		if ((!batt_measure()) && (pwmgr != PWMGR_S6)) {
			pwmgr_state_change(PWMGR_S5, 0);
		}
		return (events ^ EVT_RTC);
	}


	///////////////////////////////////////////////////////////////////////
	// battery charge detect handle                                      //
	///////////////////////////////////////////////////////////////////////
	if (events & EVT_CHARGING) {
		if (pwmgr != PWMGR_S1) {
			if (!BATCD_SBIT) {
				dmsg(("[charging]\n"));
				oled_exit_sleep();
				if ((pwmgr == PWMGR_S5) || (pwmgr == PWMGR_S6)) {
					osal_start_reload_timer(sensorTag_TaskID, EVT_RTC, PERIOD_RTC);
					pwmgr_state_change(PWMGR_S4, 0);
				}
			} else {
				dmsg(("[no charge]\n"));
				oled_enter_sleep();
			}
		}
		return (events ^ EVT_CHARGING);
	}


	///////////////////////////////////////////////////////////////////////
	// discard unknown events                                            //
	///////////////////////////////////////////////////////////////////////

	return 0;
}