TEST(PaydayTransactionForCommisionedEmployeeTest, PayrollTest) {
    ((DatabaseProxy *)getInstance())->ClearEmployees();

    int empid = 101;
    Date date(2012, 10, 10);
    double amount = 1000.00;

    AddCommisionEmployee ace(empid, "name02", "Home6", 1000.00, 0.5);
    ace.Execute();

    SalesReceiptTransaction srt(empid, date, amount);
    srt.Execute();

    Employee *e = ((DatabaseProxy *)getInstance())->GetEmployee(empid);
    PaymentClassification* pc = e->GetPaymentClassification();
    EXPECT_TRUE(pc != 0);

    CommisionClassification* cc = dynamic_cast<CommisionClassification*>(pc);
    EXPECT_TRUE(cc != 0);

    SalesReceipt receipt(cc->GetSalesReceipt(date));
    EXPECT_TRUE(receipt.GetAmount() == amount);

    Date paydate(2011, 2, 14);

    PaydayTransaction pt(paydate);
    pt.Execute();
    PayCheck *check = pt.GetPayCheck(empid);

    EXPECT_TRUE(check->GetName() == "name02");
    EXPECT_EQ(check->GetGrossPay(), 1500.00);
    EXPECT_EQ(check->GetDeductions(), 0.0);
    EXPECT_EQ(check->GetNetPay(), 1500.00);
}
Exemple #2
0
int main()
{
Point p[100];
 int n;//输入测试数据的组数
 cin>>n;

  for(int i=0;i<n;i++)//下面开始输入测试数据
  {
   cin>>p[i].x>>p[i].y;
  }
  sort(p,p+n,compare);
  result.push_back(0);//这是两上端点,不用比较,直接保存
  result.push_back(n-1);
  findleft(p,0,n-1);//调用函数
  findright(p,0,n-1);
  cout<<"组成凸包的点为:"<<endl;
  int len=result.size();
  cout<<len<<endl;
  for(int i=0;i<len;i++)
  {
  	pnt[i].x=p[result[i]].x;
  	pnt[i].y=p[result[i]].y;
  	cout<<i<<"("<<pnt[i].x<<","<<pnt[i].y<<")"<<" ";
  }
  cout<<"fsd"<<endl;
  	ace(pnt,len);
  
  result.clear();
}
TEST(DeleteEmployeeTest, PayrollTest) {

	AddCommisionEmployee ace(4, "Test4", "Shanghai", 1600.00, 0.3);
	ace.Execute();

	Employee *e = ((DatabaseProxy *)getInstance())->GetEmployee(4);
	EXPECT_TRUE(e->GetName() == "Test4");
	EXPECT_TRUE(e->GetAddress() == "Shanghai");
	EXPECT_TRUE(e->GetEmpId() == 4);

	DeleteEmployeeTransaction t(4);
	t.Execute();

	e = ((DatabaseProxy *)getInstance())->GetEmployee(4);
	EXPECT_TRUE(e == 0);
}
Exemple #4
0
bool accounts::remove_account(Account *acc) {
	if(account_list.contains(acc->proto) && account_list[acc->proto].contains(acc->account_id)) {
		AccountChanged ace(acc, this);
		ace.removed = true;
		events_i->fire_event(ace);

		account_list[acc->proto].remove(acc->account_id);

		if(account_list[acc->proto].size() == 0)
			account_list.remove(acc->proto);

		delete acc;

		return true;
	}
	return false;
}
TEST(SalesReceiptTransactionTest, PayrollTest) {
	
	int empid = 6;
	Date date(2012, 10, 10);
	double amount = 1000.00;

	AddCommisionEmployee ace(empid, "Test6", "Home6", 1000.00, 0.5);
	ace.Execute();

	SalesReceiptTransaction srt(6, date, amount);
	srt.Execute();

	Employee *e = ((DatabaseProxy *)getInstance())->GetEmployee(empid);
	PaymentClassification* pc = e->GetPaymentClassification();
	EXPECT_TRUE(pc != 0);

	CommisionClassification* cc = dynamic_cast<CommisionClassification*>(pc);
	EXPECT_TRUE(cc != 0);

	SalesReceipt receipt(cc->GetSalesReceipt(date));
	EXPECT_TRUE(receipt.GetAmount() == amount);
}
BOOL AddAceToWindowStation(HWINSTA hwinsta, PSID psid)
{
    // Obtain the DACL for the window station.
    SECURITY_INFORMATION si = DACL_SECURITY_INFORMATION;
    DWORD sd_length = 0;
    if (!GetUserObjectSecurity(hwinsta, &si, NULL, 0, &sd_length)) {
        if (GetLastError() != ERROR_INSUFFICIENT_BUFFER) {
            printf("GetUserObjectSecurity() failed: %d\n", GetLastError());
            return FALSE;
        }
    }
    auto_buffer<PSECURITY_DESCRIPTOR> psd(sd_length);
    if (!GetUserObjectSecurity(hwinsta, &si, psd.get(), sd_length, &sd_length)) {
        printf("GetUserObjectSecurity() failed: %d\n", GetLastError());
        return FALSE;
    }

    // Create a new DACL.
    auto_buffer<PSECURITY_DESCRIPTOR> psd_new(sd_length);
    if (!InitializeSecurityDescriptor(psd_new.get(), SECURITY_DESCRIPTOR_REVISION)) {
        printf("InitializeSecurityDescriptor() failed: %d\n", GetLastError());
        return FALSE;
    }

    // Get the DACL from the security descriptor.
    BOOL bDaclPresent;
    PACL pacl;
    BOOL bDaclExist;
    if (!GetSecurityDescriptorDacl(psd.get(), &bDaclPresent, &pacl, &bDaclExist)) {
        printf("GetSecurityDescriptorDacl() failed: %d\n", GetLastError());
        return FALSE;
    }
    
    // Initialize the ACL.
    ACL_SIZE_INFORMATION aclSizeInfo = {};
    aclSizeInfo.AclBytesInUse = sizeof(ACL);
    if (NULL != pacl) {
        // get the file ACL size info
        if (!GetAclInformation(pacl, &aclSizeInfo, sizeof aclSizeInfo, AclSizeInformation)) {
            printf("GetAclInformation() failed: %d\n", GetLastError());
            return FALSE;
        }
    }

    // Compute the size of the new ACL.
    DWORD new_acl_size = aclSizeInfo.AclBytesInUse +
                         (2 * sizeof(ACCESS_ALLOWED_ACE)) + 
                         (2 * GetLengthSid(psid)) - (2 * sizeof(DWORD));
    auto_buffer<PACL> new_acl(new_acl_size);

    // Initialize the new DACL.
    if (!InitializeAcl(new_acl.get(), new_acl_size, ACL_REVISION)) {
        printf("InitializeAcl() failed: %d\n", GetLastError());
        return FALSE;
    }

    // If DACL is present, copy it to a new DACL.
    if (bDaclPresent) {
        // Copy the ACEs to the new ACL.
        if (aclSizeInfo.AceCount) {
            for (DWORD i = 0; i != aclSizeInfo.AceCount; ++i) {
                LPVOID pTempAce;
                if (!GetAce(pacl, i, &pTempAce)) {
                    printf("GetAce() failed: %d\n", GetLastError());
                    return FALSE;
                }
                if (!AddAce(new_acl.get(), ACL_REVISION, MAXDWORD,
                            pTempAce, ((PACE_HEADER)pTempAce)->AceSize)) {
                    printf("AddAce() failed: %d\n", GetLastError());
                    return FALSE;
                }
            }
        }
    }

    // Add the first ACE to the window station.
    auto_buffer<ACCESS_ALLOWED_ACE*> ace(sizeof(ACCESS_ALLOWED_ACE) +
                                         GetLengthSid(psid) -
                                         sizeof(DWORD));
    ace->Header.AceType = ACCESS_ALLOWED_ACE_TYPE;
    ace->Header.AceFlags = CONTAINER_INHERIT_ACE | INHERIT_ONLY_ACE | OBJECT_INHERIT_ACE;
    ace->Header.AceSize = (WORD) (sizeof(ACCESS_ALLOWED_ACE) + GetLengthSid(psid) - sizeof(DWORD));
    ace->Mask = GENERIC_ACCESS;
    if (!CopySid(GetLengthSid(psid), &ace->SidStart, psid)) {
        printf("CopySid() failed: %d\n", GetLastError());
        return FALSE;
    }
    if (!AddAce(new_acl.get(), ACL_REVISION, MAXDWORD, ace.get(), ace->Header.AceSize)) {
        printf("AddAce() failed: %d\n", GetLastError());
        return FALSE;
    }

    // Add the second ACE to the window station.
    ace->Header.AceFlags = NO_PROPAGATE_INHERIT_ACE;
    ace->Mask = WINSTA_ALL;
    if (!AddAce(new_acl.get(), ACL_REVISION,MAXDWORD, ace.get(), ace->Header.AceSize)) {
        printf("AddAce() failed: %d\n", GetLastError());
        return FALSE;
    }

    // Set a new DACL for the security descriptor.
    if (!SetSecurityDescriptorDacl(psd_new.get(), TRUE, new_acl.get(), FALSE)) {
        printf("SetSecurityDescriptorDacl() failed: %d\n", GetLastError());
        return FALSE;
    }

    // Set the new security descriptor for the window station.
    if (!SetUserObjectSecurity(hwinsta, &si, psd_new.get())) {
        printf("SetUserObjectSecurity() failed: %d\n", GetLastError());
        return FALSE;
    }

    return TRUE;
}
Exemple #7
0
int main( int argc, char* argv[]) {

  if(argc < 6) {
    std::cout<< "All File arguments are required!!" << std::endl;
    exit(-1);
  }

  uint32_t total_frames = std::stoi(argv[1], nullptr, 10);
  uint32_t key_frame_interval = std::stoi(argv[2], nullptr, 10);
  std::string dir_path(argv[3]);
  uint32_t search_area = std::stoi(argv[4], nullptr, 10);
  int32_t vErrThreshold = std::stoi(argv[5], nullptr, 10);
  std::string out_file_path(argv[6], nullptr, 10);


#if 0
  std::string dir_path(argv[1]);
  uint32_t first_frame_idx = std::stoi(argv[2], nullptr, 10);
  uint32_t frame_count = std::stoi(argv[3], nullptr, 10);
  uint32_t search_area = std::stoi(argv[4], nullptr, 10);
  uint32_t pad_zero = std::stoi(argv[5], nullptr, 10);
  int32_t vErrThreshold = std::stoi(argv[6], nullptr, 10);  

  std::vector<std::string> file_paths;
  std::vector< std::unique_ptr<MPTC::DXTImage> > dxt_frames;

  std::stringstream ss;
  std::fstream outfile;
  outfile.open("out.txt", std::ios::out);
  //MPTC::DXTImage dxt_img(img_path, true, 0);
  ss.str("");
  ss << std::setw(pad_zero) << std::setfill('0') << first_frame_idx;
  std::string frame_num_str = ss.str();
  std::string file_path = dir_path + "/" + frame_num_str+ ".png";
  file_paths.push_back(file_path);

  MPTC::DXTImage::SetPattern(static_cast<int32_t>(search_area));

  std::unique_ptr<MPTC::DXTImage> dxt_img(new MPTC::DXTImage(file_path, true, 0, vErrThreshold));
  std::unique_ptr<MPTC::DXTImage> null_dxt(nullptr);
  dxt_frames.push_back(std::move(dxt_img));

  std::cout << "Frame Number:" << 0 << std::endl;
  std::cout << "Before PSNR: " << dxt_frames[0]->PSNR() << std::endl;
  dxt_frames[0]->Reencode(null_dxt, 0);
  std::cout << "After PSNR: " << dxt_frames[0]->PSNR() << std::endl;
  std::cout << "Intra block motion size:" << dxt_frames[0]->_motion_indices.size() << std::endl;



  std::vector<uint8_t> palette = std::move(dxt_frames[0]->Get8BitPalette());

  std::vector<uint64_t> count_palette(256, 0);
  std::vector<uint64_t> count_intra(256, 0);
  std::vector<uint64_t> total_counts(256,0);

  for(auto a : dxt_frames[0]->_intra_motion_indices) {
    count_intra[std::get<0>(a)]++;
    count_intra[std::get<1>(a)]++;
    total_counts[std::get<0>(a)]++;
    total_counts[std::get<1>(a)]++;
  }

  uint64_t Total = std::accumulate(count_intra.begin(), count_intra.end(), 0U);
  double entropy = 0.0;
  for( auto e : count_intra ) {

    if(e!=0) {
      double p = static_cast<double>(e)/static_cast<double>(Total);
      entropy += (-1.0 * p * log2(p));
    }
  }
  
  std::cout << "Total:" << Total << std::endl;
  std::cout << "Entropy:" << entropy << std::endl;
  //Entropy encode motion indices 
  
  //*****************MAX BYTES *******************
  uint32_t max_bytes = 180000;
  std::vector<uint8_t> compressed_data(max_bytes, 0);

  entropy::Arithmetic_Codec ace(max_bytes, compressed_data.data());
  entropy::Adaptive_Data_Model model(257);
  ace.start_encoder();

  for(auto a : dxt_frames[0]->_motion_indices) {
    ace.encode(std::get<0>(a), model);
    ace.encode(std::get<1>(a), model);
  }

  ace.stop_encoder();
  std::cout << "Compressed motion index bytes:" << ace.get_num_bytes() << std::endl;

  // Entropy encode index mask
  std::vector<uint8_t> compressed_mask(max_bytes, 0);
  entropy::Arithmetic_Codec ace_mask(max_bytes, compressed_mask.data());
  entropy::Adaptive_Bit_Model mask_bit_model;
  ace_mask.start_encoder();
  for(auto a : dxt_frames[0]->_index_mask) {
    ace_mask.encode(a, mask_bit_model);
  }
  ace_mask.stop_encoder();
  std::cout << "Compressed Mask bytes:" << ace_mask.get_num_bytes() << std::endl;

#if 0
  //Entropy Decode
  entropy::Arithmetic_Codec ade(max_bytes, compressed_data.data());
  entropy::Adaptive_Data_Model decode_model(257);
  ade.start_decoder();
  std::vector<std::tuple<uint8_t, uint8_t> > decoded_symbols;

  for(int i = 0; i < dxt_frames[0]->_motion_indices.size(); i++) {
    uint8_t sym1 = ade.decode(decode_model);
    uint8_t sym2 = ade.decode(decode_model);
    decoded_symbols.push_back(std::make_tuple(sym1, sym2));
#ifdef NDEBUG
    auto a = dxt_frames[0]->_motion_indices[i];
    std::cout << sym1 << "-" << std::get<0>(a) << std::endl;
    std::cout << sym2 << "-" << std::get<1>(a) << std::endl;
#endif
    assert(dxt_frames[0]->_motion_indices[i] == decoded_symbols[i]);
  }
  ade.stop_decoder();

  //Entropy decode mask bits
  entropy::Arithmetic_Codec ade_mask(max_bytes,compressed_mask.data());
  entropy::Adaptive_Bit_Model decode_mask_bit_model;
  ade_mask.start_decoder();
  std::vector<uint8_t> decoded_mask;

  for(int i = 0; i < dxt_frames[0]->_motion_indices.size(); i++) {
    uint8_t sym = ade_mask.decode(decode_mask_bit_model);
    decoded_mask.push_back(sym);
#ifndef NDEBUG
    auto a = dxt_frames[0]->_index_mask[i];
    std::cout << static_cast<int>(sym) << " -- " << static_cast<int>(a) << std::endl;
#endif 
    assert(sym == dxt_frames[0]->_index_mask[i]);
  }

  ade_mask.stop_decoder();
#endif    
  uint32_t total_bits =  ace.get_num_bytes() * 8 + dxt_frames[0]->_unique_palette.size() * 32 + ace_mask.get_num_bytes() * 8;
  float total_bytes = static_cast<float>(total_bits)/8;
  outfile << total_bytes+10 << "\t" << dxt_frames[0]->PSNR() << std::endl;
  std::cout << "*****Total bytes****:" << total_bytes << std::endl;
  float bpp = static_cast<float>(total_bits)/(dxt_frames[0]->_width * dxt_frames[0]->_height);
  std::cout << "BPP:" << bpp << "\t" << dxt_frames[0]->PSNR() <<  std::endl;
  
  std::unique_ptr<MPTC::RGBAImage> ep1 = std::move(dxt_frames[0]->EndpointOneImage());
  std::vector<uint8_t> ep1_vector = std::move(ep1->Pack());

  stbi_write_png("ep1.png", ep1->Width(), ep1->Height(),
                  4, ep1->Pack().data(), 4 * ep1->Width());


  std::unique_ptr<MPTC::RGBAImage> ep2 = std::move(dxt_frames[0]->EndpointTwoImage());
  std::vector<uint8_t> ep2_vector = std::move(ep2->Pack());

  stbi_write_png("ep2.png", ep2->Width(), ep2->Height(),
                  4, ep2->Pack().data(), 4 * ep2->Width());
 
 
  std::vector<uint32_t> ep_diff;
  int max_diff = std::numeric_limits<int>::min();
  int min_diff = std::numeric_limits<int>::max();

  std::vector<uint32_t> count_ep(512, 0);
  for(size_t ep_idx = 0; ep_idx < ep1_vector.size(); ep_idx++) {

    if(ep_idx % 4 == 3) continue;
    int diff = static_cast<int>(ep1_vector[ep_idx]) - static_cast<int>(ep2_vector[ep_idx]);
    if(diff > max_diff) max_diff = diff;
    if(diff < min_diff) min_diff = diff;
    ep_diff.push_back(static_cast<uint32_t>(diff + 255));
    count_ep[ep_diff[ep_diff.size() - 1]]++;

  }
  uint64_t Total_ep = std::accumulate(count_ep.begin(), count_ep.end(), 0U);
  double entropy_ep = 0.0;
  for( auto e : count_ep ) {

    if(e!=0) {
      double p = static_cast<double>(e)/static_cast<double>(Total_ep);
      entropy_ep += (-1.0 * p * log2(p));
    }
  }
  // Entropy encode endpoint
  std::vector<uint8_t> compressed_ep(max_bytes, 0);
  entropy::Arithmetic_Codec ace_ep(max_bytes, compressed_ep.data());
  entropy::Adaptive_Data_Model ep_model;
  ace_ep.start_encoder();
  for(auto a :ep_diff) {
    ace_ep.encode(a, mask_bit_model);
  }
  ace_ep.stop_encoder();
  std::cout << "----EndPoint compressed----:" << ace_ep.get_num_bytes() << std::endl;

  std::cout << "Total end point:" << Total_ep << std::endl;
  std::cout << "Entropy end point:" << entropy_ep << std::endl;
 
  ReconstructImage(dxt_frames, 0);
  std::cout << "PSNR after decompression: " << dxt_frames[0]->PSNR() << std::endl;

  for(uint32_t i = first_frame_idx + 1; i <= first_frame_idx + frame_count; i++) {
    ss.str("");
    ss << std::setw(pad_zero) << std::setfill('0') << i;
    std::string frame_num_str = ss.str();
    std::string file_path = dir_path + "/" + frame_num_str+ ".png";
    std::unique_ptr<MPTC::DXTImage> dxt_img1(new MPTC::DXTImage(file_path, false, search_area, vErrThreshold));

    dxt_frames.push_back(std::move(dxt_img1));
    file_paths.push_back(file_path);
  }

  double combined_bpp = bpp;
  for(size_t i = 1; i < dxt_frames.size(); i++) {
  //*****************MAX BYTES *******************

    std::cout << std::endl << std::endl;
    std::cout << "Frame Number:" << i << std::endl;
    std::cout << "Before PSNR:" << dxt_frames[i]->PSNR() << std::endl;

    dxt_frames[i]->Reencode(dxt_frames[i-1], -1);

    std::cout << "After PSNR:" << dxt_frames[i]->PSNR() << std::endl;
    std::cout << "Total unique indices:" << dxt_frames[i]->_unique_palette.size()<< std::endl;
    std::cout << "Intra block motion size:" << dxt_frames[i]->_intra_motion_indices.size()<<std::endl;
    std::cout << "Inter block motion size:" << dxt_frames[i]->_inter_block_motion_indices.size()  << std::endl;
    std::cout << "Inter pixel motion size:" << dxt_frames[i]->_inter_pixel_motion_indices.size() << std::endl;

    uint32_t max_bytes_inter = 180000;
    std::vector<uint8_t> compressed_data_inter(max_bytes_inter, 0);

    entropy::Arithmetic_Codec ace_inter(max_bytes_inter, compressed_data_inter.data());
    entropy::Adaptive_Data_Model model_inter(257);
    ace_inter.start_encoder();

    for(auto a : dxt_frames[i]->_motion_indices) {
      ace_inter.encode(std::get<0>(a), model_inter);
      ace_inter.encode(std::get<1>(a), model_inter);
    }

    ace_inter.stop_encoder();

  // Entropy encode index mask
    std::vector<uint8_t> compressed_mask_inter(max_bytes_inter, 0);
    entropy::Arithmetic_Codec ace_mask_inter(max_bytes_inter, compressed_mask_inter.data());
    entropy::Adaptive_Bit_Model mask_bit_model_inter;
    ace_mask_inter.start_encoder();
    for(auto a : dxt_frames[i]->_index_mask) {
      ace_mask_inter.encode(a, mask_bit_model_inter);
    }
    ace_mask_inter.stop_encoder();
  //Entropy Decode
  entropy::Arithmetic_Codec ade(max_bytes, compressed_data_inter.data());
  entropy::Adaptive_Data_Model decode_model(257);
  ade.start_decoder();
  std::vector<std::tuple<uint8_t, uint8_t> > decoded_symbols;

  for(int ii = 0; ii < dxt_frames[i]->_motion_indices.size(); ii++) {
    uint8_t sym1 = ade.decode(decode_model);
    uint8_t sym2 = ade.decode(decode_model);
    decoded_symbols.push_back(std::make_tuple(sym1, sym2));
#if 0
    auto a = dxt_frames[]->_motion_indices[i];
    std::cout << sym1 << "-" << std::get<0>(a) << std::endl;
    std::cout << sym2 << "-" << std::get<1>(a) << std::endl;
#endif
    assert(dxt_frames[i]->_motion_indices[ii] == decoded_symbols[ii]);
  }
  ade.stop_decoder();

  //Entropy decode mask bits
  entropy::Arithmetic_Codec ade_mask(max_bytes,compressed_mask_inter.data());
  entropy::Adaptive_Bit_Model decode_mask_bit_model;
  ade_mask.start_decoder();
  std::vector<uint8_t> decoded_mask;

  for(int ii = 0; ii < dxt_frames[i]->_index_mask.size(); ii++) {
    uint8_t sym = ade_mask.decode(decode_mask_bit_model);
    decoded_mask.push_back(sym);
#if 0
    auto a = dxt_frames[0]->_index_mask[i];
    std::cout << static_cast<int>(sym) << " -- " << static_cast<int>(a) << std::endl;
#endif 
    assert(sym == dxt_frames[i]->_index_mask[ii]);
  }

  ade_mask.stop_decoder();

    std::vector<uint64_t> counts(256,0);

    uint8_t max = std::numeric_limits<uint8_t>::min();
    uint8_t min = std::numeric_limits<uint8_t>::max();

    for(auto a : dxt_frames[i]->_motion_indices) {
      counts[std::get<0>(a)]++;
      counts[std::get<1>(a)]++;
      total_counts[std::get<0>(a)]++;
      total_counts[std::get<1>(a)]++;

      max = std::max(std::max(max, std::get<0>(a)), std::get<1>(a));
      min = std::min(std::min(min, std::get<0>(a)), std::get<1>(a));
   
    }

    Total = std::accumulate(counts.begin(), counts.end(), 0U);
    entropy = 0.0;
    for( auto e : counts ) {
      if(e!=0) {
        double p = static_cast<double>(e)/static_cast<double>(Total);
        entropy += (-1.0 * p * log2(p));
      }
    }

    std::cout << "Total:" << Total << std::endl;
    std::cout << "Entropy:" << entropy << std::endl;

    total_bits =  ace_inter.get_num_bytes() * 8 + 1000 + dxt_frames[0]->_unique_palette.size() * 32 + ace_mask_inter.get_num_bytes() * 8;
    total_bytes = static_cast<float>(total_bits)/8;

    std::cout << "Compressed motion index bytes:" << ace_inter.get_num_bytes() << std::endl;

    std::cout << "Compressed Mask bytes:" << ace_mask_inter.get_num_bytes() << std::endl;
    std::cout << "Total bytes:" << total_bytes << std::endl;
    bpp = static_cast<float>(total_bits)/(dxt_frames[0]->_width * dxt_frames[0]->_height);
    std::cout << "BPP:" << bpp << std::endl;
    combined_bpp += bpp;

  }
  std::cout << std::endl << std::endl;
  std::cout << "Combined BPP:" << combined_bpp << std::endl;
#endif
  return 0;
}