437
356
auto uploaded_file = finish_upload_fut.result();
438
357
EXPECT_EQ("some_id", uploaded_file->native_identity());
439
358
EXPECT_EQ("some_upload", uploaded_file->name());
442
QByteArray const contents = "Hello\n";
443
auto written = uploader->socket()->write(contents);
444
ASSERT_EQ(contents.size(), written);
446
auto finish_upload_fut = uploader->finish_upload();
448
QFutureWatcher<File::SPtr> w;
449
QSignalSpy spy(&w, &decltype(w)::finished);
450
w.setFuture(finish_upload_fut);
451
ASSERT_TRUE(spy.wait(SIGNAL_WAIT_TIME));
453
auto file = finish_upload_fut.result();
457
// Don't upload anything.
458
auto uploader = root->create_file("new_file").result();
459
auto file = uploader->file();
460
uploader->socket()->disconnectFromServer();
462
// We never write anything, so there is no disconnected signal from the socket.
464
auto state = uploader->finish_upload().result();
465
EXPECT_EQ(TransferState::ok, state);
466
ASSERT_EQ(0, uploader->file()->size());
468
file->delete_item().waitForFinished();
472
// Let the uploader go out of scope and check
473
// that the file was created regardless.
474
auto file = root->create_file("new_file").result()->file();
475
ASSERT_EQ(0, file->size());
477
file->delete_item().waitForFinished();
483
TEST_F(FileTest, create_uploader)
485
auto runtime = Runtime::create(connection());
487
auto acc = get_account(runtime);
488
auto root = get_root(runtime);
491
auto file = root->create_file("new_file").result()->file();
494
auto uploader = file->create_uploader(ConflictPolicy::overwrite).result();
496
auto finish_fut = uploader->finish_upload();
498
QFutureWatcher<TransferState> w;
499
QSignalSpy spy(&w, &decltype(w)::finished);
500
w.setFuture(finish_fut);
501
// We never disconnected from the socket, so the transfer is still in progress.
502
ASSERT_FALSE(spy.wait(SIGNAL_WAIT_TIME));
504
uploader->socket()->disconnectFromServer();
506
QFutureWatcher<TransferState> w;
507
QSignalSpy spy(&w, &decltype(w)::finished);
508
w.setFuture(finish_fut);
509
// Now that we have disconnected, the future must become ready.
510
ASSERT_TRUE(spy.wait(SIGNAL_WAIT_TIME));
512
EXPECT_EQ(TransferState::ok, finish_fut.result());
515
// Same test again, but this time we write a bunch of data and don't disconnect.
517
auto uploader = file->create_uploader(ConflictPolicy::overwrite).result();
519
std::string s(1000000, 'a');
520
uploader->socket()->write(&s[0], s.size());
522
auto finish_fut = uploader->finish_upload();
524
QFutureWatcher<TransferState> w;
525
QSignalSpy spy(&w, &decltype(w)::finished);
526
w.setFuture(finish_fut);
527
// We never disconnected from the socket, so the transfer is still in progress.
528
ASSERT_FALSE(spy.wait(SIGNAL_WAIT_TIME));
530
uploader->socket()->disconnectFromServer();
532
QFutureWatcher<TransferState> w;
533
QSignalSpy spy(&w, &decltype(w)::finished);
534
w.setFuture(finish_fut);
535
// Now that we have disconnected, the future must become ready.
536
ASSERT_TRUE(spy.wait(SIGNAL_WAIT_TIME));
538
EXPECT_EQ(TransferState::ok, finish_fut.result());
541
file->delete_item().waitForFinished();
544
TEST_F(FileTest, cancel_upload)
546
auto runtime = Runtime::create(connection());
548
auto acc = get_account(runtime);
549
auto root = get_root(runtime);
553
// Upload a few bytes.
554
auto uploader = root->create_file("new_file").result();
556
// We haven't written anything and haven't pumped the event loop,
557
// so the cancel is guaranteed to catch the uploader in the in_progress state.
559
EXPECT_EQ(TransferState::cancelled, uploader->finish_upload().result());
561
auto file = uploader->file();
562
EXPECT_EQ(0, file->size());
564
file->delete_item().waitForFinished();
568
// Create a file with a few bytes.
569
QByteArray original_contents = "Hello World!\n";
570
write_file(root, "new_file", original_contents);
571
auto file = dynamic_pointer_cast<File>(root->lookup("new_file").result());
572
ASSERT_NE(nullptr, file);
574
// Create an uploader for the file and write a bunch of bytes.
575
auto uploader = file->create_uploader(ConflictPolicy::overwrite).result();
576
QByteArray const contents(1024, 'a');
577
auto written = uploader->socket()->write(contents);
578
ASSERT_EQ(contents.size(), written);
580
QSignalSpy spy(uploader->socket().get(), &QLocalSocket::bytesWritten);
581
ASSERT_TRUE(spy.wait(SIGNAL_WAIT_TIME));
583
// No disconnect here, so the transfer is still in progress. Now cancel.
584
uploader->cancel().waitForFinished();
586
// finish_upload() must indicate that the upload was cancelled.
587
auto state = uploader->finish_upload().result();
588
EXPECT_EQ(TransferState::cancelled, state);
590
// The original file contents must still be intact.
591
EXPECT_EQ(original_contents.size(), uploader->file()->size());
592
ASSERT_TRUE(content_matches(uploader->file(), original_contents));
594
file->delete_item().waitForFinished();
598
// Upload a few bytes.
599
auto uploader = root->create_file("new_file").result();
600
auto file = uploader->file();
601
QByteArray const contents = "Hello\n";
603
// Finish the upload.
604
auto written = uploader->socket()->write(contents);
605
ASSERT_EQ(contents.size(), written);
606
uploader->socket()->disconnectFromServer();
608
// Pump the event loop for a bit, so the socket can finish doing its thing.
610
QSignalSpy spy(&timer, &QTimer::timeout);
611
timer.start(SIGNAL_WAIT_TIME);
612
ASSERT_TRUE(spy.wait(SIGNAL_WAIT_TIME));
614
// Now send the cancel. The upload is finished already, and the cancel
615
// is too late, so finish_upload() must report that the upload
618
EXPECT_EQ(TransferState::ok, uploader->finish_upload().result());
620
file->delete_item().waitForFinished();
624
TEST_F(FileTest, upload_conflict)
626
auto runtime = Runtime::create(connection());
628
auto acc = get_account(runtime);
629
auto root = get_root(runtime);
633
auto uploader = root->create_file("new_file").result();
634
auto file = uploader->file();
636
// Write a few bytes.
637
QByteArray const contents = "Hello\n";
639
// Pump the event loop for a bit, so the socket can finish doing its thing.
641
QSignalSpy spy(&timer, &QTimer::timeout);
642
timer.start(SIGNAL_WAIT_TIME);
643
ASSERT_TRUE(spy.wait(SIGNAL_WAIT_TIME));
645
// Touch the file on disk to give it a new time stamp.
646
ASSERT_EQ(0, system((string("touch ") + file->native_identity().toStdString()).c_str()));
648
// Finish the upload.
649
uploader->socket()->disconnectFromServer();
361
TEST_F(RootTest, root_exceptions)
363
auto runtime = Runtime::create(connection());
365
auto root = get_root(runtime);
653
// Must get an exception because the time stamps no longer match.
654
uploader->finish_upload().result();
370
call(root->delete_item());
657
catch (ConflictException const&)
659
// TODO: check exception details.
662
file->delete_item().waitForFinished();
665
TEST_F(FileTest, download)
667
auto runtime = Runtime::create(connection());
669
auto acc = get_account(runtime);
670
auto root = get_root(runtime);
674
// Download a few bytes.
675
QByteArray const contents = "Hello\n";
676
write_file(root, "file", contents);
678
auto item = root->lookup("file").result();
679
File::SPtr file = dynamic_pointer_cast<File>(item);
680
ASSERT_FALSE(file == nullptr);
682
auto downloader = file->create_downloader().result();
683
EXPECT_TRUE(file->equal_to(downloader->file()));
685
auto socket = downloader->socket();
689
// Need to pump the event loop while the socket does its thing.
690
QSignalSpy spy(downloader->socket().get(), &QIODevice::readyRead);
691
ASSERT_TRUE(spy.wait(SIGNAL_WAIT_TIME));
692
auto bytes_to_read = socket->bytesAvailable();
693
buf.append(socket->read(bytes_to_read));
694
} while (buf.size() < contents.size());
696
// Wait for disconnected signal.
697
QSignalSpy spy(downloader->socket().get(), &QLocalSocket::disconnected);
698
ASSERT_TRUE(spy.wait(SIGNAL_WAIT_TIME));
700
auto state = downloader->finish_download().result();
701
EXPECT_EQ(TransferState::ok, state);
703
// Contents must match.
704
EXPECT_EQ(contents, buf);
708
// Download exactly 64 KB.
709
QByteArray const contents(64 * 1024, 'a');
710
write_file(root, "file", contents);
712
auto item = root->lookup("file").result();
713
File::SPtr file = dynamic_pointer_cast<File>(item);
714
ASSERT_FALSE(file == nullptr);
716
auto downloader = file->create_downloader().result();
717
EXPECT_TRUE(file->equal_to(downloader->file()));
719
auto socket = downloader->socket();
723
// Need to pump the event loop while the socket does its thing.
724
QSignalSpy spy(downloader->socket().get(), &QIODevice::readyRead);
725
ASSERT_TRUE(spy.wait(SIGNAL_WAIT_TIME));
726
auto bytes_to_read = socket->bytesAvailable();
727
buf.append(socket->read(bytes_to_read));
728
} while (buf.size() < contents.size());
730
// Wait for disconnected signal.
731
QSignalSpy spy(downloader->socket().get(), &QLocalSocket::disconnected);
732
ASSERT_TRUE(spy.wait(SIGNAL_WAIT_TIME));
734
auto state = downloader->finish_download().result();
735
EXPECT_EQ(TransferState::ok, state);
737
// Contents must match
738
EXPECT_EQ(contents, buf);
742
// Download 1 MB + 1 bytes.
743
QByteArray const contents(1024 * 1024 + 1, 'a');
744
write_file(root, "file", contents);
746
auto item = root->lookup("file").result();
747
File::SPtr file = dynamic_pointer_cast<File>(item);
748
ASSERT_FALSE(file == nullptr);
750
auto downloader = file->create_downloader().result();
751
EXPECT_TRUE(file->equal_to(downloader->file()));
753
auto socket = downloader->socket();
757
// Need to pump the event loop while the socket does its thing.
758
QSignalSpy spy(downloader->socket().get(), &QIODevice::readyRead);
759
ASSERT_TRUE(spy.wait(SIGNAL_WAIT_TIME));
760
auto bytes_to_read = socket->bytesAvailable();
761
buf.append(socket->read(bytes_to_read));
762
} while (buf.size() < contents.size());
764
// Wait for disconnected signal.
765
QSignalSpy spy(downloader->socket().get(), &QLocalSocket::disconnected);
766
ASSERT_TRUE(spy.wait(SIGNAL_WAIT_TIME));
768
auto state = downloader->finish_download().result();
769
EXPECT_EQ(TransferState::ok, state);
771
// Contents must match
772
EXPECT_EQ(contents, buf);
776
// Download file containing zero bytes
777
QByteArray const contents;
778
write_file(root, "file", contents);
780
auto item = root->lookup("file").result();
781
File::SPtr file = dynamic_pointer_cast<File>(item);
782
ASSERT_FALSE(file == nullptr);
784
auto downloader = file->create_downloader().result();
785
EXPECT_TRUE(file->equal_to(downloader->file()));
787
auto socket = downloader->socket();
789
// No readyRead every arrives in this case, just wait for disconnected.
790
QSignalSpy spy(downloader->socket().get(), &QLocalSocket::disconnected);
791
ASSERT_TRUE(spy.wait(SIGNAL_WAIT_TIME));
793
auto state = downloader->finish_download().result();
794
EXPECT_EQ(TransferState::ok, state);
798
// Don't ever call read on empty file.
799
QByteArray const contents;
800
write_file(root, "file", contents);
802
auto item = root->lookup("file").result();
803
File::SPtr file = dynamic_pointer_cast<File>(item);
804
ASSERT_FALSE(file == nullptr);
806
auto downloader = file->create_downloader().result();
807
EXPECT_TRUE(file->equal_to(downloader->file()));
809
// This succeeds because the provider disconnects as soon
810
// as it realizes that there is nothing to write.
811
downloader->finish_download().result();
815
// Don't ever call read on non-empty file.
816
QByteArray const contents("some contents");
817
write_file(root, "file", contents);
819
auto item = root->lookup("file").result();
820
File::SPtr file = dynamic_pointer_cast<File>(item);
821
ASSERT_FALSE(file == nullptr);
823
auto downloader = file->create_downloader().result();
824
EXPECT_TRUE(file->equal_to(downloader->file()));
828
downloader->finish_download().result();
831
catch (StorageException const&)
833
// TODO: check exception details
838
// Let downloader go out of scope.
839
QByteArray const contents("some contents");
840
write_file(root, "file", contents);
842
auto item = root->lookup("file").result();
843
File::SPtr file = dynamic_pointer_cast<File>(item);
844
ASSERT_FALSE(file == nullptr);
846
auto downloader = file->create_downloader().result();
850
// Let downloader future go out of scope.
851
QByteArray const contents("some contents");
852
write_file(root, "file", contents);
854
auto item = root->lookup("file").result();
855
File::SPtr file = dynamic_pointer_cast<File>(item);
856
ASSERT_FALSE(file == nullptr);
858
auto downloader_fut = file->create_downloader();
862
TEST_F(FileTest, cancel_download)
864
auto runtime = Runtime::create(connection());
866
auto acc = get_account(runtime);
867
auto root = get_root(runtime);
871
// Download enough bytes to prevent a single read in the provider from completing the download.
872
QByteArray const contents(1024 * 1024, 'a');
873
write_file(root, "file", contents);
875
auto item = root->lookup("file").result();
876
File::SPtr file = dynamic_pointer_cast<File>(item);
877
ASSERT_FALSE(file == nullptr);
879
auto downloader = file->create_downloader().result();
880
// We haven't read anything and haven't pumped the event loop,
881
// so the cancel is guaranteed to catch the downloader in the in_progress state.
882
downloader->cancel();
883
EXPECT_EQ(TransferState::cancelled, downloader->finish_download().result());
887
// Download a few bytes.
888
QByteArray const contents = "Hello\n";
889
write_file(root, "file", contents);
891
auto item = root->lookup("file").result();
892
File::SPtr file = dynamic_pointer_cast<File>(item);
893
ASSERT_FALSE(file == nullptr);
895
// Finish the download.
896
auto downloader = file->create_downloader().result();
897
auto socket = downloader->socket();
901
// Need to pump the event loop while the socket does its thing.
902
QSignalSpy spy(downloader->socket().get(), &QIODevice::readyRead);
903
ASSERT_TRUE(spy.wait(SIGNAL_WAIT_TIME));
904
auto bytes_to_read = socket->bytesAvailable();
905
buf.append(socket->read(bytes_to_read));
906
} while (buf.size() < contents.size());
908
// Wait for disconnected signal.
909
QSignalSpy spy(downloader->socket().get(), &QLocalSocket::disconnected);
910
ASSERT_TRUE(spy.wait(SIGNAL_WAIT_TIME));
912
// Now send the cancel. The download is finished already, and the cancel
913
// is too late, so finish_download() must report that the download
915
downloader->cancel();
916
EXPECT_EQ(TransferState::ok, downloader->finish_download().result());
920
Test_F(ItemTest, move)
922
auto runtime = Runtime::create(connection());
924
auto acc = get_account(runtime);
925
auto root = get_root(runtime);
928
// Check that rename works within the same folder.
929
auto f1 = root->create_file("f1").result()->file();
930
auto f2 = f1->move(root, "f2").result();
931
EXPECT_EQ("f2", f2->name());
932
EXPECT_THROW(f1->name(), DestroyedException); // TODO: check exception details.
934
// File must be found under new name.
935
auto items = root->list().result();
936
ASSERT_EQ(1, items.size());
937
f2 = dynamic_pointer_cast<File>(items[0]);
938
ASSERT_FALSE(f2 == nullptr);
940
// Make a folder and move f2 into it.
941
auto folder = root->create_folder("folder").result();
942
f2 = f2->move(folder, "f2").result();
943
EXPECT_TRUE(get_parent(f2)->equal_to(folder));
946
auto item = folder->move(root, "folder2").result();
947
folder = dynamic_pointer_cast<Folder>(item);
948
EXPECT_EQ("folder2", folder->name());
951
Test_F(ItemTest, copy)
953
auto runtime = Runtime::create(connection());
955
auto acc = get_account(runtime);
956
auto root = get_root(runtime);
959
QByteArray const contents = "hello\n";
960
write_file(root, "file", contents);
962
auto item = root->lookup("file").result();
963
auto copied_item = item->copy(root, "copy_of_file").result();
964
EXPECT_EQ("copy_of_file", copied_item->name());
965
File::SPtr copied_file = dynamic_pointer_cast<File>(item);
966
ASSERT_NE(nullptr, copied_file);
967
EXPECT_TRUE(content_matches(copied_file, contents));
970
Test_F(ItemTest, recursive_copy)
972
auto runtime = Runtime::create(connection());
974
auto acc = get_account(runtime);
975
auto root = get_root(runtime);
978
// Create the following structure:
980
// folder/empty_folder
981
// folder/non_empty_folder
982
// folder/non_empty_folder/nested_file
985
string root_path = root->native_identity().toStdString();
986
ASSERT_EQ(0, mkdir((root_path + "/folder").c_str(), 0700));
987
ASSERT_EQ(0, mkdir((root_path + "/folder/empty_folder").c_str(), 0700));
988
ASSERT_EQ(0, mkdir((root_path + "/folder/non_empty_folder").c_str(), 0700));
989
ofstream(root_path + "/folder/non_empty_folder/nested_file");
990
ofstream(root_path + "/folder/file");
992
// Copy folder to folder2
993
auto folder = dynamic_pointer_cast<Folder>(root->lookup("folder").result());
994
ASSERT_NE(nullptr, folder);
995
auto item = folder->copy(root, "folder2").result();
997
// Verify that folder2 now contains the same structure as folder.
998
auto folder2 = dynamic_pointer_cast<Folder>(item);
999
ASSERT_NE(nullptr, folder2);
1000
EXPECT_NO_THROW(folder2->lookup("empty_folder").result());
1001
item = folder2->lookup("non_empty_folder").result();
1002
auto non_empty_folder = dynamic_pointer_cast<Folder>(item);
1003
ASSERT_NE(nullptr, non_empty_folder);
1004
EXPECT_NO_THROW(non_empty_folder->lookup("nested_file").result());
1005
EXPECT_NO_THROW(folder2->lookup("file").result());
1008
Test_F(ItemTest, modified_time)
1010
auto runtime = Runtime::create(connection());
1012
auto acc = get_account(runtime);
1013
auto root = get_root(runtime);
1016
auto now = QDateTime::currentDateTimeUtc();
1017
// Need to sleep because time_t provides only 1-second resolution.
1019
auto file = root->create_file("file").result()->file();
1020
auto t = file->last_modified_time();
1021
// Rough check that the time is sane.
1023
EXPECT_LE(t, now.addSecs(5));
1026
Test_F(ItemTest, comparison)
1028
auto runtime = Runtime::create(connection());
1030
auto acc = get_account(runtime);
1031
auto root = get_root(runtime);
1034
// Create two files.
1035
auto file1 = root->create_file("file1").result()->file();
1036
auto file2 = root->create_file("file2").result()->file();
1038
EXPECT_FALSE(file1->equal_to(file2));
1040
// Retrieve file1 via lookup, so we get a different proxy.
1041
auto item = root->lookup("file1").result();
1042
auto other_file1 = dynamic_pointer_cast<File>(item);
1043
EXPECT_NE(file1, other_file1); // Compares shared_ptr values
1044
EXPECT_TRUE(file1->equal_to(other_file1)); // Deep comparison
373
catch (LogicException const& e)
375
EXPECT_EQ("Item::delete_item(): cannot delete root folder", e.error_message()) << e.what();
381
call(root->get("no_such_file_id"));
384
catch (NotExistsException const& e)
386
EXPECT_EQ("no_such_file_id", e.key());
391
TEST_F(RuntimeTest, runtime_destroyed_exceptions)
393
// Gettting an account after shutting down the runtime must fail.
395
auto runtime = Runtime::create(connection());
396
auto acc = get_account(runtime);
403
catch (RuntimeDestroyedException const& e)
405
EXPECT_EQ("Account::runtime(): runtime was destroyed previously", e.error_message());
409
// Getting an account after destroying the runtime must fail.
411
auto runtime = Runtime::create(connection());
412
auto acc = get_account(runtime);
419
catch (RuntimeDestroyedException const& e)
421
EXPECT_EQ("Account::runtime(): runtime was destroyed previously", e.error_message());
425
// Getting accounts after shutting down the runtime must fail.
427
auto runtime = Runtime::create(connection());
431
call(runtime->accounts());
434
catch (RuntimeDestroyedException const& e)
436
EXPECT_EQ("Runtime::accounts(): runtime was destroyed previously", e.error_message());
440
// Getting the account from a root with a destroyed runtime must fail.
442
auto runtime = Runtime::create(connection());
443
auto root = get_root(runtime);
450
catch (RuntimeDestroyedException const& e)
452
EXPECT_EQ("Root::account(): runtime was destroyed previously", e.error_message());
456
// Getting the account from a root with a destroyed account must fail.
458
auto runtime = Runtime::create(connection());
459
auto acc = get_account(runtime);
460
auto root = get_root(runtime);
468
catch (RuntimeDestroyedException const& e)
470
EXPECT_EQ("Root::account(): runtime was destroyed previously", e.error_message());
474
// Getting the root from an item with a destroyed runtime must fail.
476
auto runtime = Runtime::create(connection());
477
auto root = get_root(runtime);
480
auto file = dynamic_pointer_cast<File>(call(root->get("child_id")));
487
catch (RuntimeDestroyedException const& e)
489
EXPECT_EQ("Item::root(): runtime was destroyed previously", e.error_message());
493
// Getting the root from an item with a destroyed root must fail.
495
auto runtime = Runtime::create(connection());
496
auto acc = get_account(runtime);
497
auto root = get_root(runtime);
500
auto file = dynamic_pointer_cast<File>(call(root->get("child_id")));
509
catch (RuntimeDestroyedException const& e)
511
EXPECT_EQ("Item::root(): runtime was destroyed previously", e.error_message());
515
// etag() with destroyed runtime must fail.
517
auto runtime = Runtime::create(connection());
518
auto root = get_root(runtime);
521
auto file = dynamic_pointer_cast<File>(call(root->get("child_id")));
528
catch (RuntimeDestroyedException const& e)
530
EXPECT_EQ("Item::etag(): runtime was destroyed previously", e.error_message());
534
// metadata() with destroyed runtime must fail.
536
auto runtime = Runtime::create(connection());
537
auto root = get_root(runtime);
540
auto file = dynamic_pointer_cast<File>(call(root->get("child_id")));
547
catch (RuntimeDestroyedException const& e)
549
EXPECT_EQ("Item::metadata(): runtime was destroyed previously", e.error_message());
553
// last_modified_time() with destroyed runtime must fail.
555
auto runtime = Runtime::create(connection());
556
auto root = get_root(runtime);
559
auto file = dynamic_pointer_cast<File>(call(root->get("child_id")));
563
file->last_modified_time();
566
catch (RuntimeDestroyedException const& e)
568
EXPECT_EQ("Item::last_modified_time(): runtime was destroyed previously", e.error_message());
572
// copy() with destroyed runtime must fail.
574
auto runtime = Runtime::create(connection());
575
auto root = get_root(runtime);
578
auto file = dynamic_pointer_cast<File>(call(root->get("child_id")));
582
call(file->copy(root, "file2"));
585
catch (RuntimeDestroyedException const& e)
587
EXPECT_EQ("Item::copy(): runtime was destroyed previously", e.error_message());
591
// move() with destroyed runtime must fail.
593
auto runtime = Runtime::create(connection());
594
auto root = get_root(runtime);
597
auto file = dynamic_pointer_cast<File>(call(root->get("child_id")));
601
call(file->move(root, "file2"));
604
catch (RuntimeDestroyedException const& e)
606
EXPECT_EQ("Item::move(): runtime was destroyed previously", e.error_message());
610
// parents() on root with destroyed runtime must fail.
612
auto runtime = Runtime::create(connection());
613
auto root = get_root(runtime);
619
call(root->parents());
622
catch (RuntimeDestroyedException const& e)
624
EXPECT_EQ("Root::parents(): runtime was destroyed previously", e.error_message());
628
// parents() on file with destroyed runtime must fail.
630
auto runtime = Runtime::create(connection());
631
auto root = get_root(runtime);
634
auto file = dynamic_pointer_cast<File>(call(root->get("child_id")));
638
call(file->parents());
641
catch (RuntimeDestroyedException const& e)
643
EXPECT_EQ("Item::parents(): runtime was destroyed previously", e.error_message());
647
// parent_ids() with destroyed runtime must fail.
649
auto runtime = Runtime::create(connection());
650
auto root = get_root(runtime);
653
auto file = dynamic_pointer_cast<File>(call(root->get("child_id")));
660
catch (RuntimeDestroyedException const& e)
662
EXPECT_EQ("Item::parent_ids(): runtime was destroyed previously", e.error_message());
666
// parent_ids() on root with destroyed runtime must fail.
668
auto runtime = Runtime::create(connection());
669
auto root = get_root(runtime);
678
catch (RuntimeDestroyedException const& e)
680
EXPECT_EQ("Root::parent_ids(): runtime was destroyed previously", e.error_message());
684
// delete_item() with destroyed runtime must fail.
686
auto runtime = Runtime::create(connection());
687
auto root = get_root(runtime);
690
auto file = dynamic_pointer_cast<File>(call(root->get("child_id")));
694
call(file->delete_item());
697
catch (RuntimeDestroyedException const& e)
699
EXPECT_EQ("Item::delete_item(): runtime was destroyed previously", e.error_message());
703
// delete_item() on root with destroyed runtime must fail.
705
auto runtime = Runtime::create(connection());
706
auto root = get_root(runtime);
712
call(root->delete_item());
715
catch (RuntimeDestroyedException const& e)
717
EXPECT_EQ("Item::delete_item(): runtime was destroyed previously", e.error_message());
721
// creation_time() with destroyed runtime must fail.
723
auto runtime = Runtime::create(connection());
724
auto root = get_root(runtime);
727
auto file = dynamic_pointer_cast<File>(call(root->get("child_id")));
731
file->creation_time();
734
catch (RuntimeDestroyedException const& e)
736
EXPECT_EQ("Item::creation_time(): runtime was destroyed previously", e.error_message());
740
// native_metadata() with destroyed runtime must fail.
742
auto runtime = Runtime::create(connection());
743
auto root = get_root(runtime);
746
auto file = dynamic_pointer_cast<File>(call(root->get("child_id")));
750
file->native_metadata();
753
catch (RuntimeDestroyedException const& e)
755
EXPECT_EQ("Item::native_metadata(): runtime was destroyed previously", e.error_message());
759
// name() on root with destroyed runtime must fail.
761
auto runtime = Runtime::create(connection());
762
auto root = get_root(runtime);
771
catch (RuntimeDestroyedException const& e)
773
EXPECT_EQ("Item::name(): runtime was destroyed previously", e.error_message());
777
// name() on folder with destroyed runtime must fail.
779
auto runtime = Runtime::create(connection());
780
auto root = get_root(runtime);
783
auto folder = dynamic_pointer_cast<Folder>(call(root->get("child_folder_id")));
790
catch (RuntimeDestroyedException const& e)
792
EXPECT_EQ("Item::name(): runtime was destroyed previously", e.error_message());
796
// name() on file with destroyed runtime must fail.
798
auto runtime = Runtime::create(connection());
799
auto root = get_root(runtime);
802
auto file = dynamic_pointer_cast<File>(call(root->get("child_id")));
809
catch (RuntimeDestroyedException const& e)
811
EXPECT_EQ("Item::name(): runtime was destroyed previously", e.error_message());
815
// list() with destroyed runtime must fail.
817
auto runtime = Runtime::create(connection());
818
auto root = get_root(runtime);
827
catch (RuntimeDestroyedException const& e)
829
EXPECT_EQ("Folder::list(): runtime was destroyed previously", e.error_message());
833
// lookup() with destroyed runtime must fail.
835
auto runtime = Runtime::create(connection());
836
auto root = get_root(runtime);
842
call(root->lookup("file"));
845
catch (RuntimeDestroyedException const& e)
847
EXPECT_EQ("Folder::lookup(): runtime was destroyed previously", e.error_message());
851
// create_folder() with destroyed runtime must fail.
853
auto runtime = Runtime::create(connection());
854
auto root = get_root(runtime);
860
call(root->create_folder("folder"));
863
catch (RuntimeDestroyedException const& e)
865
EXPECT_EQ("Folder::create_folder(): runtime was destroyed previously", e.error_message());
869
// create_file() with destroyed runtime must fail.
871
auto runtime = Runtime::create(connection());
872
auto root = get_root(runtime);
878
call(root->create_file("file", 0));
881
catch (RuntimeDestroyedException const& e)
883
EXPECT_EQ("Folder::create_file(): runtime was destroyed previously", e.error_message());
887
// size() with destroyed runtime must fail.
889
auto runtime = Runtime::create(connection());
890
auto root = get_root(runtime);
893
auto file = dynamic_pointer_cast<File>(call(root->get("child_id")));
900
catch (RuntimeDestroyedException const& e)
902
EXPECT_EQ("File::size(): runtime was destroyed previously", e.error_message());
906
// create_uploader() with destroyed runtime must fail.
908
auto runtime = Runtime::create(connection());
909
auto root = get_root(runtime);
912
auto file = dynamic_pointer_cast<File>(call(root->get("child_id")));
916
call(file->create_uploader(ConflictPolicy::overwrite, 0));
919
catch (RuntimeDestroyedException const& e)
921
EXPECT_EQ("File::create_uploader(): runtime was destroyed previously", e.error_message()) << e.what();
925
// create_downloader() with destroyed runtime must fail.
927
auto runtime = Runtime::create(connection());
928
auto root = get_root(runtime);
931
auto file = dynamic_pointer_cast<File>(call(root->get("child_id")));
935
call(file->create_downloader());
938
catch (RuntimeDestroyedException const& e)
940
EXPECT_EQ("File::create_downloader(): runtime was destroyed previously", e.error_message());
944
// free_space_bytes() with destroyed runtime must fail.
946
auto runtime = Runtime::create(connection());
947
auto root = get_root(runtime);
953
call(root->free_space_bytes());
956
catch (RuntimeDestroyedException const& e)
958
EXPECT_EQ("Root::free_space_bytes(): runtime was destroyed previously", e.error_message());
962
// used_space_bytes() with destroyed runtime must fail.
964
auto runtime = Runtime::create(connection());
965
auto root = get_root(runtime);
971
call(root->used_space_bytes());
974
catch (RuntimeDestroyedException const& e)
976
EXPECT_EQ("Root::used_space_bytes(): runtime was destroyed previously", e.error_message());
980
// get() with destroyed runtime must fail.
982
auto runtime = Runtime::create(connection());
983
auto root = get_root(runtime);
989
call(root->get("some_id"));
992
catch (RuntimeDestroyedException const& e)
994
EXPECT_EQ("Root::get(): runtime was destroyed previously", e.error_message());
1048
999
int main(int argc, char** argv)