v0.1.1.5: Enhanced text format support (plaintext, syntax highlighting, markdown); comprehensive testing and documentation
This commit is contained in:
@ -26,22 +26,27 @@ int main() {
|
||||
std::cout << "[test] PRIVATEBIN_IT not set; skipping integration test." << std::endl;
|
||||
return 0; // treat as success when integration testing is disabled
|
||||
}
|
||||
|
||||
const char* server = "https://privatebin.medisoftware.org/";
|
||||
const char* content = "Integration test from lib-privatebin";
|
||||
const char* password = nullptr; // no password
|
||||
const char* expiration = "5min"; // short-lived
|
||||
const char* format = "plaintext";
|
||||
const int burn_after_reading = 0;
|
||||
const int open_discussion = 0;
|
||||
|
||||
std::cout << "[test] Testing different text formats..." << std::endl;
|
||||
|
||||
// Test 1: Plaintext format
|
||||
std::cout << "[test] 1. Testing plaintext format..." << std::endl;
|
||||
const char* plaintext_content = "Integration test from lib-privatebin - plaintext";
|
||||
const char* plaintext_format = "plaintext";
|
||||
|
||||
char* paste_url = nullptr;
|
||||
char* delete_token = nullptr;
|
||||
|
||||
std::cout << "[test] create_paste..." << std::endl;
|
||||
int rc = create_paste(server, content, password, expiration, format,
|
||||
int rc = create_paste(server, plaintext_content, password, expiration, plaintext_format,
|
||||
burn_after_reading, open_discussion, &paste_url, &delete_token);
|
||||
if (rc != 0 || paste_url == nullptr || delete_token == nullptr) {
|
||||
std::cerr << "[test][ERROR] create_paste failed, rc=" << rc << std::endl;
|
||||
std::cerr << "[test][ERROR] plaintext create_paste failed, rc=" << rc << std::endl;
|
||||
if (paste_url) free_string(paste_url);
|
||||
if (delete_token) free_string(delete_token);
|
||||
return 1;
|
||||
@ -68,7 +73,7 @@ int main() {
|
||||
return 1;
|
||||
}
|
||||
std::string fetched_str = fetched;
|
||||
assert(fetched_str == content && "fetched content mismatch");
|
||||
assert(fetched_str == plaintext_content && "fetched plaintext content mismatch");
|
||||
|
||||
std::cout << "[test] delete_paste..." << std::endl;
|
||||
rc = delete_paste(server, paste_id.c_str(), delete_token);
|
||||
@ -80,11 +85,142 @@ int main() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
// cleanup
|
||||
// cleanup plaintext test
|
||||
free_string(paste_url);
|
||||
free_string(delete_token);
|
||||
free_string(fetched);
|
||||
|
||||
// Test 2: Syntax highlighting format
|
||||
std::cout << "[test] 2. Testing syntax highlighting format..." << std::endl;
|
||||
const char* code_content = R"(
|
||||
#include <iostream>
|
||||
|
||||
std::cout << "[test] all API functions passed." << std::endl;
|
||||
int main() {
|
||||
std::cout << "Hello, World!" << std::endl;
|
||||
return 0;
|
||||
}
|
||||
)";
|
||||
const char* code_format = "syntaxhighlighting";
|
||||
|
||||
char* code_paste_url = nullptr;
|
||||
char* code_delete_token = nullptr;
|
||||
|
||||
rc = create_paste(server, code_content, password, expiration, code_format,
|
||||
burn_after_reading, open_discussion, &code_paste_url, &code_delete_token);
|
||||
if (rc != 0 || code_paste_url == nullptr || code_delete_token == nullptr) {
|
||||
std::cerr << "[test][ERROR] syntax highlighting create_paste failed, rc=" << rc << std::endl;
|
||||
if (code_paste_url) free_string(code_paste_url);
|
||||
if (code_delete_token) free_string(code_delete_token);
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Parse code paste URL
|
||||
std::string code_full_url = code_paste_url;
|
||||
std::string code_paste_id;
|
||||
std::string code_key;
|
||||
const bool code_ok_parse = extract_paste_id_and_key(code_full_url, code_paste_id, code_key);
|
||||
if (!code_ok_parse) {
|
||||
std::cerr << "[test][ERROR] failed to parse code paste id/key from URL: " << code_full_url << std::endl;
|
||||
free_string(code_paste_url);
|
||||
free_string(code_delete_token);
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Fetch and verify code paste
|
||||
char* code_fetched = nullptr;
|
||||
rc = get_paste(server, code_paste_id.c_str(), code_key.c_str(), &code_fetched);
|
||||
if (rc != 0 || code_fetched == nullptr) {
|
||||
std::cerr << "[test][ERROR] code get_paste failed, rc=" << rc << std::endl;
|
||||
free_string(code_paste_url);
|
||||
free_string(code_delete_token);
|
||||
return 1;
|
||||
}
|
||||
std::string code_fetched_str = code_fetched;
|
||||
assert(code_fetched_str == code_content && "fetched code content mismatch");
|
||||
|
||||
// Delete code paste
|
||||
rc = delete_paste(server, code_paste_id.c_str(), code_delete_token);
|
||||
if (rc != 0) {
|
||||
std::cerr << "[test][ERROR] code delete_paste failed, rc=" << rc << std::endl;
|
||||
free_string(code_paste_url);
|
||||
free_string(code_delete_token);
|
||||
free_string(code_fetched);
|
||||
return 1;
|
||||
}
|
||||
|
||||
// cleanup code test
|
||||
free_string(code_paste_url);
|
||||
free_string(code_delete_token);
|
||||
free_string(code_fetched);
|
||||
|
||||
// Test 3: Markdown format
|
||||
std::cout << "[test] 3. Testing markdown format..." << std::endl;
|
||||
const char* markdown_content = R"(
|
||||
# Test Header
|
||||
|
||||
This is a **bold** and *italic* text.
|
||||
|
||||
## Code Block
|
||||
```cpp
|
||||
int x = 42;
|
||||
std::cout << x << std::endl;
|
||||
```
|
||||
|
||||
> This is a blockquote.
|
||||
)";
|
||||
const char* markdown_format = "markdown";
|
||||
|
||||
char* markdown_paste_url = nullptr;
|
||||
char* markdown_delete_token = nullptr;
|
||||
|
||||
rc = create_paste(server, markdown_content, password, expiration, markdown_format,
|
||||
burn_after_reading, open_discussion, &markdown_paste_url, &markdown_delete_token);
|
||||
if (rc != 0 || markdown_paste_url == nullptr || markdown_delete_token == nullptr) {
|
||||
std::cerr << "[test][ERROR] markdown create_paste failed, rc=" << rc << std::endl;
|
||||
if (markdown_paste_url) free_string(markdown_paste_url);
|
||||
if (markdown_delete_token) free_string(markdown_delete_token);
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Parse markdown paste URL
|
||||
std::string markdown_full_url = markdown_paste_url;
|
||||
std::string markdown_paste_id;
|
||||
std::string markdown_key;
|
||||
const bool markdown_ok_parse = extract_paste_id_and_key(markdown_full_url, markdown_paste_id, markdown_key);
|
||||
if (!markdown_ok_parse) {
|
||||
std::cerr << "[test][ERROR] failed to parse markdown paste id/key from URL: " << markdown_full_url << std::endl;
|
||||
free_string(markdown_paste_url);
|
||||
free_string(markdown_delete_token);
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Fetch and verify markdown paste
|
||||
char* markdown_fetched = nullptr;
|
||||
rc = get_paste(server, markdown_paste_id.c_str(), markdown_key.c_str(), &markdown_fetched);
|
||||
if (rc != 0 || markdown_fetched == nullptr) {
|
||||
std::cerr << "[test][ERROR] markdown get_paste failed, rc=" << rc << std::endl;
|
||||
free_string(markdown_paste_url);
|
||||
free_string(markdown_delete_token);
|
||||
return 1;
|
||||
}
|
||||
std::string markdown_fetched_str = markdown_fetched;
|
||||
assert(markdown_fetched_str == markdown_content && "fetched markdown content mismatch");
|
||||
|
||||
// Delete markdown paste
|
||||
rc = delete_paste(server, markdown_paste_id.c_str(), markdown_delete_token);
|
||||
if (rc != 0) {
|
||||
std::cerr << "[test][ERROR] markdown delete_paste failed, rc=" << rc << std::endl;
|
||||
free_string(markdown_paste_url);
|
||||
free_string(markdown_delete_token);
|
||||
free_string(markdown_fetched);
|
||||
return 1;
|
||||
}
|
||||
|
||||
// cleanup markdown test
|
||||
free_string(markdown_paste_url);
|
||||
free_string(markdown_delete_token);
|
||||
free_string(markdown_fetched);
|
||||
|
||||
std::cout << "[test] All format tests passed successfully!" << std::endl;
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user