upd:测试uptask用例完成。

This commit is contained in:
taynpg 2025-04-13 13:22:35 +08:00
parent 414bc6ed75
commit 13423d5172
7 changed files with 162 additions and 8 deletions

View File

@ -6,6 +6,8 @@ BreakBeforeBraces: Custom
BraceWrapping:
AfterFunction: true
AfterClass: true
AfterLambdaBody: false
BeforeLambdaBody: false
Cpp11BracedListStyle: true
ReflowComments: true
SpacesBeforeTrailingComments: 3

View File

@ -724,7 +724,11 @@ bool TransmClient::cmd_sub_task(const std::string& param, bool is_send)
return false;
}
#ifdef USE_TRANSM_TEST
auto handel_ret = handle_user_select(mre, false);
#else
auto handel_ret = handle_user_select(mre, is_send);
#endif
if (handel_ret.empty()) {
TLOGE("handle_user_select not pass, abort action!");
return false;
@ -1396,9 +1400,11 @@ void TransmClient::send_file_data_th(const char* keys)
// ********************************************************
// seekg 用于读,seekp 用于写。
t->file_.seekg(0, std::ios::end);
long long size = t->file_.tellg();
t->file_.seekg(0, std::ios::beg);
// t->file_.seekg(0, std::ios::end);
// long long size = t->file_.tellg();
// t->file_.seekg(0, std::ios::beg);
auto size = fs::file_size(t->cur_file_);
buf->type_ = TYPE_FILE_INFO;
std::string str_size = std::to_string(size);

View File

@ -156,6 +156,7 @@ bool exec_cmd(CmdParam& param, bool& run)
int main(int argc, char* argv[])
{
#ifdef _WIN32
HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
DWORD mode;

@ -1 +1 @@
Subproject commit 4b6612cc63f21b4d092a0b5731ceb7f817f20d23
Subproject commit 2a59b1066a076fc27157992aa4adbe39d2758cb5

View File

@ -5,6 +5,7 @@
#include "../client/client.h"
#include "../client/config.h"
#include "../server/server.h"
#include "../util/util.h"
#include "assistant.h"
std::shared_ptr<TransmServer> server;
@ -31,7 +32,7 @@ std::string test_task_file = "test_task.txt";
bool test_ls();
bool random_ralated_files();
bool test_up_task();
bool test_up_task(bool encrypt);
void server_run()
{
@ -90,6 +91,11 @@ bool base_connect()
bool main_test()
{
ON_SCOPE_EXIT
{
fc_recovery_color();
};
if (!base_connect()) {
return false;
}
@ -119,7 +125,11 @@ bool main_test()
return false;
}
if (!test_up_task()) {
if (!test_up_task(true)) {
return false;
}
if (!test_up_task(false)) {
return false;
}
@ -137,12 +147,53 @@ bool test_ls()
return true;
}
bool test_up_task()
bool test_up_task(bool encrypt)
{
std::string cmd = std::to_string(ida_in_b) + " " + test_task_file;
auto fas = test_filea;
auto fat = test_sub_dir + "/" + test_filea;
auto fbs = test_fileb;
auto fbt = test_sub_dir + "/" + test_fileb;
ON_SCOPE_EXIT
{
if (fs::exists(fat)) {
fs::remove(fat);
}
if (fs::exists(fbt)) {
fs::remove(fbt);
}
};
set_encrypt(encrypt);
clientB->set_task_state(TransmClient::TaskState::TASK_STATE_IDLE);
if (!clientB->cmd_sub_task(cmd, true)) {
return false;
}
if (value_wait<TransmClient::TaskState>(
[&]() -> TransmClient::TaskState { return clientB->get_task_state(); },
TransmClient::TaskState::TASK_STATE_IDLE, std::not_equal_to<TransmClient::TaskState>(),
max_wait * 2, wait_interval) == false) {
return false;
}
auto r = clientB->get_task_state();
if (r != TransmClient::TaskState::TASK_STATE_DONE) {
return false;
}
if (!is_equal_filecontent(fas, fat)) {
return false;
}
if (!is_equal_filecontent(fbs, fbt)) {
return false;
}
std::cout << "****** up task done encrypt:" << encrypt << " ******" << std::endl;
std::this_thread::sleep_for(std::chrono::milliseconds(100));
return true;
}

View File

@ -30,4 +30,48 @@ bool random_file(const std::string& file, size_t size)
remaining -= chunk;
}
return true;
}
/**
* @brief
*
* @param filea
* @param fileb
* @return true
* @return false
*/
bool is_equal_filecontent(const std::string& filea, const std::string& fileb)
{
std::ifstream stream_a(filea, std::ios::binary);
std::ifstream stream_b(fileb, std::ios::binary);
if (!stream_a.is_open() || !stream_b.is_open()) {
return false;
}
auto size_a = fs::file_size(filea);
auto size_b = fs::file_size(fileb);
if (size_a != size_b) {
return false;
}
const size_t buffer_size = 4096; // 4KB 缓冲区
char buffer_a[buffer_size];
char buffer_b[buffer_size];
while (stream_a.good() && stream_b.good()) {
stream_a.read(buffer_a, buffer_size);
stream_b.read(buffer_b, buffer_size);
if (stream_a.gcount() != stream_b.gcount()) {
return false;
}
if (!std::equal(buffer_a, buffer_a + stream_a.gcount(), buffer_b)) {
return false;
}
}
return !stream_a.bad() && !stream_b.bad();
}

View File

@ -2,9 +2,9 @@
#define ASSISTANT_H
#include <fstream>
#include <functional>
#include <random>
#include <string>
#include <functional>
#ifdef USE_BOOST
#include <boost/filesystem.hpp>
@ -14,6 +14,15 @@ namespace fs = boost::filesystem;
namespace fs = std::filesystem;
#endif
/**
* @brief
*
* @param filea
* @param fileb
* @return true
* @return false
*/
bool is_equal_filecontent(const std::string& filea, const std::string& fileb);
bool random_file(const std::string& file, size_t size);
/**
@ -55,4 +64,45 @@ bool value_wait(const std::function<T()>& value_ref, const T& expected, Compare
}
}
class ScopeExit
{
public:
ScopeExit() = default;
template <typename F> ScopeExit(F&& f) : func_(std::forward<F>(f))
{
}
ScopeExit(const ScopeExit&) = delete;
ScopeExit& operator=(const ScopeExit&) = delete;
ScopeExit(ScopeExit&& other) noexcept : func_(std::move(other.func_))
{
other.func_ = nullptr;
}
ScopeExit& operator=(ScopeExit&& other) noexcept
{
if (this != &other) {
if (func_)
func_();
func_ = std::move(other.func_);
other.func_ = nullptr;
}
return *this;
}
~ScopeExit()
{
if (func_)
func_();
}
void dismiss() noexcept
{
func_ = nullptr;
}
private:
std::function<void()> func_;
};
#define _SCOPE_EXIT_CONCAT(a, b) a##b
#define _MAKE_ON_SCOPE_EXIT(line) ScopeExit _SCOPE_EXIT_CONCAT(exit_defer_, line) = [&]()
#define ON_SCOPE_EXIT _MAKE_ON_SCOPE_EXIT(__LINE__)
#endif // ASSISTANT_H