Add build test for the file dialog helper

This commit is contained in:
Kovid Goyal 2016-05-11 07:42:16 +05:30
parent 7128d6eadd
commit 6838ffc42c
3 changed files with 28 additions and 3 deletions

View File

@ -94,7 +94,7 @@ static void print_com_error(HRESULT hr, const char *msg) {
int sz = 0; int sz = 0;
const char *buf = to_utf8(emsg, &sz); const char *buf = to_utf8(emsg, &sz);
if (buf == NULL) { fprintf(stderr, "%s", msg); } if (buf == NULL) { fprintf(stderr, "%s", msg); }
else { fprintf(stderr, "%s: (HRESULT=0x%x) %s\n", msg, hr, emsg); } else { fprintf(stderr, "%s: (HRESULT=0x%x) %s\n", msg, hr, buf); }
fflush(stderr); fflush(stderr);
} }
@ -188,7 +188,7 @@ int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PWSTR pCmdLine
HWND parent = NULL; HWND parent = NULL;
bool save_dialog = false, multiselect = false, confirm_overwrite = false, only_dirs = false, no_symlinks = false; bool save_dialog = false, multiselect = false, confirm_overwrite = false, only_dirs = false, no_symlinks = false;
unsigned short len = 0; unsigned short len = 0;
LPWSTR title = NULL, folder = NULL, filename = NULL, save_path = NULL; LPWSTR title = NULL, folder = NULL, filename = NULL, save_path = NULL, echo = NULL;
COMDLG_FILTERSPEC *file_types = NULL; COMDLG_FILTERSPEC *file_types = NULL;
UINT num_file_types = 0; UINT num_file_types = 0;
@ -208,7 +208,7 @@ int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PWSTR pCmdLine
READ(sizeof(HWND), buf); READ(sizeof(HWND), buf);
if (sizeof(HWND) == 8) parent = (HWND)*((__int64*)buf); if (sizeof(HWND) == 8) parent = (HWND)*((__int64*)buf);
else if (sizeof(HWND) == 4) parent = (HWND)*((__int32*)buf); else if (sizeof(HWND) == 4) parent = (HWND)*((__int32*)buf);
else { fprintf(stderr, "Unknown pointer size: %d", sizeof(HWND)); fflush(stderr); return 1;} else { fprintf(stderr, "Unknown pointer size: %zd", sizeof(HWND)); fflush(stderr); return 1;}
} }
else if CHECK_KEY("TITLE") { READSTR(title) } else if CHECK_KEY("TITLE") { READSTR(title) }
@ -231,11 +231,20 @@ int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PWSTR pCmdLine
else if CHECK_KEY("FILE_TYPES") { file_types = read_file_types(&num_file_types); if (file_types == NULL) return 1; } else if CHECK_KEY("FILE_TYPES") { file_types = read_file_types(&num_file_types); if (file_types == NULL) return 1; }
else if CHECK_KEY("ECHO") { READSTR(echo) }
else { else {
PRINTERR("Unknown key"); PRINTERR("Unknown key");
return 1; return 1;
} }
} }
if (echo != NULL) {
int echo_sz = 0;
char *echo_buf = to_utf8(echo, &echo_sz);
fprintf(stdout, "%s", echo_buf);
return 0;
}
return show_dialog(parent, save_dialog, title, folder, filename, save_path, multiselect, confirm_overwrite, only_dirs, no_symlinks, file_types, num_file_types); return show_dialog(parent, save_dialog, title, folder, filename, save_path, multiselect, confirm_overwrite, only_dirs, no_symlinks, file_types, num_file_types);
} }

View File

@ -151,8 +151,18 @@ def run_file_dialog(
ans = tuple((os.path.abspath(x.decode('utf-8')) for x in h.stdoutdata.split(b'\0') if x)) ans = tuple((os.path.abspath(x.decode('utf-8')) for x in h.stdoutdata.split(b'\0') if x))
return ans return ans
def test():
p = subprocess.Popen([HELPER], stdout=subprocess.PIPE, stdin=subprocess.PIPE, stderr=subprocess.PIPE)
echo = '\U0001f431 Hello world!'
stdout, stderr = p.communicate(serialize_string('ECHO', echo))
if p.wait() != 0:
raise Exception('File dialog failed: ' + stderr.decode('utf-8'))
if stdout.decode('utf-8') != echo:
raise RuntimeError('Unexpected response: %s' % stdout.decode('utf-8'))
if __name__ == '__main__': if __name__ == '__main__':
HELPER = sys.argv[-1] HELPER = sys.argv[-1]
test()
app = QApplication([]) app = QApplication([])
q = QMainWindow() q = QMainWindow()
_ = lambda x: x _ = lambda x: x

View File

@ -177,6 +177,11 @@ def test_imaging():
raise RuntimeError('PIL choked!') raise RuntimeError('PIL choked!')
fprint('PIL OK!') fprint('PIL OK!')
def test_file_dialog_helper():
from calibre.gui2.win_file_dialogs import test
test()
print('File dialog helper OK!')
def test_unrar(): def test_unrar():
from calibre.utils.unrar import test_basic from calibre.utils.unrar import test_basic
test_basic() test_basic()
@ -304,6 +309,7 @@ def test():
if iswindows: if iswindows:
test_wpd() test_wpd()
test_winutil() test_winutil()
test_file_dialog_helper()
else: else:
test_terminal() test_terminal()
if isosx: if isosx: