Revision 1238 branches/threaded2merge/tests/threads/msimple/tests_adthread_manager.cpp

tests_adthread_manager.cpp (revision 1238)
1 1
#include <gtest/gtest.h>
2 2
#include <fvar.hpp>
3 3
#include <adthread.h>
4
#include <string>
4 5

  
5 6
class tests_adthread_manager: public ::testing::Test {};
6 7

  
......
313 314
  pthread_join(ptlock, NULL);
314 315
  ASSERT_EQ(2, count);
315 316
}
317
TEST_F(tests_adthread_buffer, int_binary_to_stdstring)
318
{
319
  const size_t sizeofint = sizeof(int);
320

  
321
  std::string str;
322
  int value = 123789;
323
  char* ptr = (char*)&value;
324
  str.append(ptr, sizeofint);
325
  int expected = 0;
326
  char* ptr2 = (char*)&expected;
327
  memcpy(ptr2, str.c_str(), sizeofint);
328
  ASSERT_EQ(expected, value);
329

  
330
  int value2 = 456321;
331
  ptr = (char*)&value2;
332
  str.append(ptr, sizeofint);
333
  const char* ptr3 = str.c_str();
334
  memcpy(ptr2, &ptr3[sizeofint], sizeofint);
335
  ASSERT_EQ(expected, value2);
336
}
337
TEST_F(tests_adthread_buffer, double_binary_to_stdstring)
338
{
339
  const size_t sizeofdouble = sizeof(double);
340

  
341
  std::string str;
342
  double value = 123789.456321;
343
  char* ptr = (char*)&value;
344
  str.append(ptr, sizeofdouble);
345
  double expected = 0;
346
  char* ptr2 = (char*)&expected;
347
  memcpy(ptr2, str.c_str(), sizeofdouble);
348
  ASSERT_EQ(expected, value);
349

  
350
  double value2 = 456321.123789;
351
  ptr = (char*)&value2;
352
  str.append(ptr, sizeofdouble);
353
  const char* ptr3 = str.c_str();
354
  memcpy(ptr2, &ptr3[sizeofdouble], sizeofdouble);
355
  ASSERT_EQ(expected, value2);
356
}
357
TEST_F(tests_adthread_buffer, push_pop_int)
358
{
359
  adthread_buffer a;
360
  const int value = 123789;
361
  a.push(value);
362
  int expected = 0;
363
  a.pop(expected);
364
  ASSERT_EQ(expected, value);
365
}
366
TEST_F(tests_adthread_buffer, push_pop_int_3x)
367
{
368
  adthread_buffer a;
369

  
370
  const int expected1 = 123789;
371
  a.push(expected1);
372
  const int expected2 = 72891;
373
  a.push(expected2);
374
  const int expected3 = 789123;
375
  a.push(expected3);
376

  
377
  int value3 = 0;
378
  a.pop(value3);
379
  ASSERT_EQ(expected3, value3);
380

  
381
  int value2 = 0;
382
  a.pop(value2);
383
  ASSERT_EQ(expected2, value2);
384

  
385
  int value1 = 0;
386
  a.pop(value1);
387
  ASSERT_EQ(expected1, value1);
388
}
389
TEST_F(tests_adthread_buffer, push_pop_double)
390
{
391
  adthread_buffer a;
392
  const double expected = 123789.9876;
393
  a.push(expected);
394
  double value = 0;
395
  a.pop(value);
396
  ASSERT_EQ(expected, value);
397
}
398
TEST_F(tests_adthread_buffer, push_pop_double_3x)
399
{
400
  adthread_buffer a;
401

  
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff