Mercurial > hg > orthanc
comparison UnitTestsSources/RestApiTests.cpp @ 3399:4e8205871967
OrthancPluginRegisterMultipartRestCallback() is working
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Fri, 07 Jun 2019 14:14:31 +0200 |
parents | 4acd1431e603 |
children | 94f4a18a79cc |
comparison
equal
deleted
inserted
replaced
3398:4acd1431e603 | 3399:4e8205871967 |
---|---|
722 }; | 722 }; |
723 | 723 |
724 std::vector<Part> parts_; | 724 std::vector<Part> parts_; |
725 | 725 |
726 public: | 726 public: |
727 virtual void Apply(const MultipartStreamReader::HttpHeaders& headers, | 727 virtual void HandlePart(const MultipartStreamReader::HttpHeaders& headers, |
728 const void* part, | 728 const void* part, |
729 size_t size) | 729 size_t size) |
730 { | 730 { |
731 parts_.push_back(Part(headers, part, size)); | 731 parts_.push_back(Part(headers, part, size)); |
732 } | 732 } |
733 | 733 |
734 unsigned int GetCount() const | 734 unsigned int GetCount() const |
748 }; | 748 }; |
749 | 749 |
750 | 750 |
751 TEST(MultipartStreamReader, ParseHeaders) | 751 TEST(MultipartStreamReader, ParseHeaders) |
752 { | 752 { |
753 std::string ct, b, st; | 753 std::string ct, b, st, header; |
754 | 754 |
755 { | 755 { |
756 MultipartStreamReader::HttpHeaders h; | 756 MultipartStreamReader::HttpHeaders h; |
757 h["hello"] = "world"; | 757 h["hello"] = "world"; |
758 h["Content-Type"] = "world"; // Should be in lower-case | 758 h["Content-Type"] = "world"; // Should be in lower-case |
759 h["CONTENT-type"] = "world"; // Should be in lower-case | 759 h["CONTENT-type"] = "world"; // Should be in lower-case |
760 ASSERT_FALSE(MultipartStreamReader::GetMainContentType(ct, h)); | 760 ASSERT_FALSE(MultipartStreamReader::GetMainContentType(header, h)); |
761 ASSERT_FALSE(MultipartStreamReader::ParseMultipartHeaders(ct, st, b, h)); | |
762 } | 761 } |
763 | 762 |
764 { | 763 { |
765 MultipartStreamReader::HttpHeaders h; | 764 MultipartStreamReader::HttpHeaders h; |
766 h["content-type"] = "world"; | 765 h["content-type"] = "world"; |
767 ASSERT_TRUE(MultipartStreamReader::GetMainContentType(ct, h)); | 766 ASSERT_TRUE(MultipartStreamReader::GetMainContentType(header, h)); |
768 ASSERT_EQ(ct, "world"); | 767 ASSERT_EQ(header, "world"); |
769 ASSERT_FALSE(MultipartStreamReader::ParseMultipartHeaders(ct, st, b, h)); | 768 ASSERT_FALSE(MultipartStreamReader::ParseMultipartContentType(ct, st, b, header)); |
770 } | 769 } |
771 | 770 |
772 { | 771 { |
773 MultipartStreamReader::HttpHeaders h; | 772 MultipartStreamReader::HttpHeaders h; |
774 h["content-type"] = "multipart/related; dummy=value; boundary=1234; hello=world"; | 773 h["content-type"] = "multipart/related; dummy=value; boundary=1234; hello=world"; |
775 ASSERT_TRUE(MultipartStreamReader::GetMainContentType(ct, h)); | 774 ASSERT_TRUE(MultipartStreamReader::GetMainContentType(header, h)); |
776 ASSERT_EQ(ct, h["content-type"]); | 775 ASSERT_EQ(header, h["content-type"]); |
777 ASSERT_TRUE(MultipartStreamReader::ParseMultipartHeaders(ct, st, b, h)); | 776 ASSERT_TRUE(MultipartStreamReader::ParseMultipartContentType(ct, st, b, header)); |
778 ASSERT_EQ(ct, "multipart/related"); | 777 ASSERT_EQ(ct, "multipart/related"); |
779 ASSERT_EQ(b, "1234"); | 778 ASSERT_EQ(b, "1234"); |
780 ASSERT_TRUE(st.empty()); | 779 ASSERT_TRUE(st.empty()); |
781 } | 780 } |
782 | 781 |
783 { | 782 { |
784 MultipartStreamReader::HttpHeaders h; | 783 ASSERT_FALSE(MultipartStreamReader::ParseMultipartContentType |
785 h["content-type"] = "multipart/related; boundary="; | 784 (ct, st, b, "multipart/related; boundary=")); // Empty boundary |
786 ASSERT_TRUE(MultipartStreamReader::GetMainContentType(ct, h)); | 785 } |
787 ASSERT_EQ(ct, h["content-type"]); | 786 |
788 ASSERT_FALSE(MultipartStreamReader::ParseMultipartHeaders(ct, st, b, h)); // Empty boundary | 787 { |
789 } | 788 ASSERT_TRUE(MultipartStreamReader::ParseMultipartContentType |
790 | 789 (ct, st, b, "Multipart/Related; TYPE=Application/Dicom; Boundary=heLLO")); |
791 { | |
792 MultipartStreamReader::HttpHeaders h; | |
793 h["content-type"] = "Multipart/Related; TYPE=Application/Dicom; Boundary=heLLO"; | |
794 ASSERT_TRUE(MultipartStreamReader::ParseMultipartHeaders(ct, st, b, h)); | |
795 ASSERT_EQ(ct, "multipart/related"); | 790 ASSERT_EQ(ct, "multipart/related"); |
796 ASSERT_EQ(b, "heLLO"); | 791 ASSERT_EQ(b, "heLLO"); |
797 ASSERT_EQ(st, "application/dicom"); | 792 ASSERT_EQ(st, "application/dicom"); |
798 } | 793 } |
799 | 794 |
800 { | 795 { |
801 MultipartStreamReader::HttpHeaders h; | 796 ASSERT_TRUE(MultipartStreamReader::ParseMultipartContentType |
802 h["content-type"] = "Multipart/Related; type=\"application/DICOM\"; Boundary=a"; | 797 (ct, st, b, "Multipart/Related; type=\"application/DICOM\"; Boundary=a")); |
803 ASSERT_TRUE(MultipartStreamReader::ParseMultipartHeaders(ct, st, b, h)); | |
804 ASSERT_EQ(ct, "multipart/related"); | 798 ASSERT_EQ(ct, "multipart/related"); |
805 ASSERT_EQ(b, "a"); | 799 ASSERT_EQ(b, "a"); |
806 ASSERT_EQ(st, "application/dicom"); | 800 ASSERT_EQ(st, "application/dicom"); |
807 } | 801 } |
808 } | 802 } |